Package com.volantis.devrep.repository.accessors

Examples of com.volantis.devrep.repository.accessors.EclipseDeviceRepository


        TemporaryFileManager manager = new TemporaryFileManager(
                new TestDeviceRepositoryCreator());
        manager.executeWith(new TemporaryFileExecutor() {
            public void execute(File repository) throws Exception {
                // Create a temporary repository which will be deleted later.
                EclipseDeviceRepository accessor = updateHierarchy(
                        getHierarchy(), repository.getPath());

                // Should write the repository atomically (preserve original if
                // write fails).
                writeRepository(accessor);
                assertTrue("Repository should exist", repository.exists());

                File backupRepository = new File(repository.getPath() + ".bak");
                assertFalse("Backup repository should NOT exist",
                        backupRepository.exists());


                Document hierarchyDoc = (Document)
                        PrivateAccessor.getField(accessor, "xmlHierarchyDocument");

                Element root = hierarchyDoc.getRootElement();
                Element master = root.getChild("device", root.getNamespace());
                Element newDevice = new Element("device", root.getNamespace());
                newDevice.setAttribute("name", "FakeDevice");
                master.addContent(newDevice);

                accessor.writeHierarchy();
                accessor.saveRepositoryArchive();

                ZipArchive archive = (ZipArchive)
                        PrivateAccessor.getField(accessor, "repositoryArchive");
                InputStream input = archive.getInputFrom("hierarchy.xml");
                if (input != null) {
                    hierarchyDoc = accessor.createNewDocument(
                            new BufferedInputStream(input));
                }

                root = hierarchyDoc.getRootElement();
                master = root.getChild("device", root.getNamespace());
View Full Code Here


        TemporaryFileManager manager = new TemporaryFileManager(
                new TestDeviceRepositoryCreator());
        manager.executeWith(new TemporaryFileExecutor() {
            public void execute(File repository) throws Exception {
                // Create a temporary repository which will be deleted later.
                EclipseDeviceRepository accessor = updateHierarchy(
                        getHierarchy(), repository.getPath());

                // Should write the repository atomically (preserve original if
                // write fails).
                writeRepository(accessor);
                assertTrue("Repository should exist", repository.exists());

                File backupRepository = new File(repository.getPath() + ".bak");
                assertFalse("Backup repository should NOT exist",
                        backupRepository.exists());

                Element root = accessor.
                        getDevicePolicyDefinitions().getRootElement();

                List children = root.getChildren();
                Element customCat = null;
                for (int i = 0; i < children.size() && customCat == null; i++) {
                    Element child = (Element) children.get(i);
                    if (child.getName().equals("category")) {
                        String nameAtt = child.getAttributeValue("name");
                        if (nameAtt != null && nameAtt.equals("custom")) {
                            customCat = child;
                        }
                    }
                }
                if (customCat == null) {
                    customCat = new Element("category", root.getNamespace());
                    customCat.setAttribute("name", "custom");
                    root.addContent(customCat);
                }

                Element policy = new Element("policy", root.getNamespace());
                policy.setAttribute("name", "wibble");
                Element type = new Element("type", root.getNamespace());
                policy.addContent(type);
                Element bool = new Element("boolean", root.getNamespace());
                type.addContent(bool);
                customCat.addContent(policy);

                accessor.writeDefinitions();
                accessor.saveRepositoryArchive();

                boolean savedNewDefinition = false;
                root = accessor.getDevicePolicyDefinitions().getRootElement();
                children = root.getChildren();
                for (int i = 0; i < children.size(); i++) {
                    Element element = (Element) children.get(i);
                    if (element.getName().equals("category")) {
                        String name = element.getAttributeValue("name");
View Full Code Here

        TemporaryFileManager manager = new TemporaryFileManager(
                new TestDeviceRepositoryCreator());
        manager.executeWith(new TemporaryFileExecutor() {
            public void execute(File repository) throws Exception {
                // Create a temporary repository which will be deleted later.
                EclipseDeviceRepository accessor = updateHierarchy(
                        getHierarchy(), repository.getPath());

                // Should write the repository atomically (preserve original if
                // write fails).
                writeRepository(accessor);
                assertTrue("Repository should exist", repository.exists());

                File backupRepository = new File(repository.getPath() + ".bak");
                assertFalse("Backup repository should NOT exist",
                        backupRepository.exists());

                Element root = accessor.
                        getDevicePolicyDefinitions().getRootElement();

                assertNotNull("New policy definition was not saved and retrieved.",
                        root);
            }
View Full Code Here

        TemporaryFileManager manager = new TemporaryFileManager(
                new TestDeviceRepositoryCreator());
        manager.executeWith(new TemporaryFileExecutor() {
            public void execute(File repository) throws Exception {
                // Create a temporary repository which will be deleted later.
                EclipseDeviceRepository accessor = updateHierarchy(
                        getHierarchy(), repository.getPath());

                // Should write the repository atomically (preserve original if
                // write fails).
                writeRepository(accessor);
                assertTrue("Repository should exist", repository.exists());

                File backupRepository = new File(repository.getPath() + ".bak");
                assertFalse("Backup repository should NOT exist",
                        backupRepository.exists());

                Map devices = new HashMap();
                Element device = accessor.retrieveDeviceElement("PC");
                Element policy = retrievePolicy(device, "rendermode");
                policy.setAttribute("value", "wibble");
                devices.put("PC", device);

                accessor.writeDeviceElements(devices);
                accessor.saveRepositoryArchive();

                // now retrieve the policy from the repository again to see if we
                // actually wrote it out.
                device = accessor.retrieveDeviceElement("PC");
                policy = retrievePolicy(device, "rendermode");
                assertEquals("Should have seen a different value for the policy.",
                        "wibble", policy.getAttributeValue("value"));
            }
        });
View Full Code Here

                        "<policy name=\"ssl\" value=\"true\"/>";
                String newDevice = createDeviceElementString(policies);
                Map deviceMap = new HashMap();
                deviceMap.put("NewDevice", JDOMUtils.createElement(newDevice));

                EclipseDeviceRepository accessor =
                        new EclipseDeviceRepository(repository.getPath(),
                                transformerMetaFactory, jdomFactory, true, true, null);

                // write out the fred device
                accessor.writeDeviceElements(deviceMap);
                accessor.saveRepositoryArchive();

                ZipFile afterZip = new ZipFile(repository);
                try {
                    assertNotNull("standard device should exist",
                            afterZip.getEntry("standard/devices/NewDevice.xml"));
View Full Code Here

                        "<policy name=\"custom.ssl\" value=\"true\"/>";
                String newDevice = createDeviceElementString(policies);
                Map deviceMap = new HashMap();
                deviceMap.put("NewDevice", JDOMUtils.createElement(newDevice));

                EclipseDeviceRepository accessor =
                        new EclipseDeviceRepository(repository.getPath(),
                                transformerMetaFactory, jdomFactory, true, true, null);

                // write out the fred device
                accessor.writeDeviceElements(deviceMap);
                accessor.saveRepositoryArchive();

                ZipFile afterZip = new ZipFile(repository);
                try {
                    assertNotNull("standard device should exist",
                            afterZip.getEntry("standard/devices/NewDevice.xml"));
View Full Code Here

                Map deviceMap = new HashMap();
                String newDevice = createDeviceElementString(policies);
                deviceMap.put("NewDevice", JDOMUtils.createElement(newDevice));

                EclipseDeviceRepository accessor =
                        new EclipseDeviceRepository(repository.getPath(),
                                transformerMetaFactory, jdomFactory, true, true, null);

                // write out the fred device
                accessor.writeDeviceElements(deviceMap);
                accessor.saveRepositoryArchive();

                ZipFile afterZip = new ZipFile(repository);
                try {
                    assertNotNull("standard NewDevice device should exist",
                            afterZip.getEntry("standard/devices/NewDevice.xml"));
View Full Code Here

        TemporaryFileManager manager = new TemporaryFileManager(
                new TestDeviceRepositoryCreator());
        manager.executeWith(new TemporaryFileExecutor() {
            public void execute(File repository) throws Exception {
                // Create a temporary repository which will be deleted later.
                EclipseDeviceRepository accessor = updateHierarchy(
                        getHierarchy(), repository.getPath());

                // Should write the repository atomically (preserve original if
                // write fails).
                writeRepository(accessor);
                assertTrue("Repository should exist", repository.exists());

                File backupRepository = new File(repository.getPath() + ".bak");
                assertFalse("Backup repository should NOT exist",
                        backupRepository.exists());

                Element device = accessor.retrieveDeviceElement("PC");
                Element policies = device.getChild("policies", device.getNamespace());
                Element newPolicy = new Element("policy", device.getNamespace());
                newPolicy.setAttribute("name", "custom.mypolicy");
                newPolicy.setAttribute("value", "xyz");
                policies.addContent(newPolicy);

                Map devices = new HashMap();
                devices.put("PC", device);
                ArrayList list = new ArrayList(1);
                list.add(device);
                accessor.writeDeviceElements(devices);
                accessor.saveRepositoryArchive();

                ZipArchive archive = (ZipArchive)
                        PrivateAccessor.getField(accessor, "repositoryArchive");
                device = retrieveCustomDeviceElement(accessor, archive, "PC");
                Element policy = retrievePolicy(device, "custom.mypolicy");
                assertEquals("Should have seen a different value for the policy.",
                        "xyz", policy.getAttributeValue("value"));

                device = retrieveStandardDeviceElement(accessor, archive, "PC");
                policy = retrievePolicy(device, "custom.mypolicy");
                assertNull("policy should not have been found.", policy);


                // now retrieve the policy from the repository again to see if we
                // actually wrote it out.
                device = accessor.retrieveDeviceElement("PC");
                policy = retrievePolicy(device, "custom.mypolicy");
                assertEquals("Should have seen a different value for the policy.",
                        "xyz", policy.getAttributeValue("value"));
            }
        });
View Full Code Here

                FileExtension.DEVICE_REPOSITORY.getExtension());

        // Construct a bunch of testable devices using the underlying
        // accessor
        // @todo later refactor so it doesn't use the internal device API
        EclipseDeviceRepository accessor =
            new EclipseDeviceRepository(deviceRepository.getPath(),
                    transformerMetaFactory, new DefaultJDOMFactory(), null);

        int i = 0;
        HashMap nameToProfile = new HashMap();
        for (Iterator keys = deviceToProfile.keySet().iterator();
             keys.hasNext();) {
            // Extract the next deviceValue.
            DeviceValue deviceValue = (DeviceValue)keys.next();

            // Create a synthetic name for it.
            i += 1;
            String deviceName = "mytest-device-" + i;

            // Add the expected profile value for this device value to the
            // results map.
            nameToProfile.put(deviceName, deviceToProfile.get(deviceValue));

            accessor.addHierarchyDeviceElement(
                    deviceName, accessor.getRootDeviceName());

            // Add the created device for this device value to the
            // repository.
            HashMap deviceProps = new HashMap();
            deviceProps.put("pixeldepth", deviceValue.pixeldepth);
            deviceProps.put("rendermode", deviceValue.rendermode);
            deviceProps.put("modelnum", deviceValue.modelnum);
            deviceProps.put("pixelsx", deviceValue.pixelsx);
            deviceProps.put("pixelsy", deviceValue.pixelsy);
            deviceProps.put("charactersx", deviceValue.charactersx);
            deviceProps.put("charactersy", deviceValue.charactersy);
            deviceProps.put("mfg", deviceValue.mfg);
            deviceProps.put("UAProf.CcppAccept", deviceValue.uaprofCcppAccept);
            deviceProps.put("brwsrname", deviceValue.brwsrname);
            deviceProps.put("brwsrvers", deviceValue.brwsrvers);
            deviceProps.put("UAProf.WmlVersion", deviceValue.uaprofWmlVersion);

            org.jdom.Element deviceElement = createDeviceElement(deviceProps);
            Map devices = new HashMap(1);
            devices.put(deviceName, deviceElement);
            accessor.writeDeviceElements(devices);
            accessor.writeHierarchy();
        }

        accessor.saveRepositoryArchive();

        // Connect to a single file XML repository.
        HashMap repositoryProps = new HashMap();
        repositoryProps.put(XMLRepository.DEVICE_REPOSITORY_PROPERTY,
                            deviceRepository.getPath());
View Full Code Here

                                repository.getPath(), transformerMetaFactory,
                                jdomFactory, false);

                // Grab the accessor before anything is executed so that it can be
                // used for comparison after each static test
                EclipseDeviceRepository accessor = (EclipseDeviceRepository)
                        PrivateAccessor.getField(manager, "accessor");

                // Test the method
                checkSelection(
                        DeviceRepositoryAccessorManager.selectHierarchyDevices(
View Full Code Here

TOP

Related Classes of com.volantis.devrep.repository.accessors.EclipseDeviceRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.