Package org.openengsb.core.workflow.drools.model

Examples of org.openengsb.core.workflow.drools.model.RuleBaseElement


        assertFalse(service.supports(GlobalConfiguration.class));
    }

    @Test
    public void testPersistRuleBaseElement_shouldCreateFileAndLoad() throws Exception {
        RuleBaseElement element = new RuleBaseElement();
        element.setCode("code");
        element.setName("name");
        element.setPackageName("package.org");
        element.setType(RuleBaseElementType.Rule);

        RuleBaseConfiguration conf = new RuleBaseConfiguration(element);
        service.persist(conf);

        String expectedFilename =
            String.format("%s%s%s%s%s", element.getType(), separator, element.getName(), separator
                , encoder.encode(element.getPackageName()));
        File expectedTarget = new File(storageFolder, expectedFilename);
        assertTrue(expectedTarget.exists());
        String code = FileUtils.readFileToString(expectedTarget);
        assertEquals("code", code);

        List<ConfigItem<RuleBaseElement>> loaded = service.load(conf.getMetaData());
        assertEquals(1, loaded.size());
        RuleBaseElement loadedElement = loaded.get(0).getContent();
        assertEquals(element.getName(), loadedElement.getName());
        assertEquals(element.getCode(), loadedElement.getCode());
        assertEquals(element.getPackageName(), loadedElement.getPackageName());
        assertEquals(element.getType(), loadedElement.getType());

    }
View Full Code Here


    private RuleBaseConfiguration readConfigFile(File file) throws PersistenceException {
        LOGGER.debug("reading configfile \"{}\"", file);
        String[] parts = file.getName().split(SEPARATOR);

        RuleBaseElement element = new RuleBaseElement();
        element.setType(RuleBaseElementType.valueOf(parts[0]));

        try {
            element.setName(encoder.decode(parts[1]));
            element.setPackageName(encoder.decode(parts[2]));
            element.setCode(FileUtils.readFileToString(file));
        } catch (IOException e) {
            throw new PersistenceException(e);
        } catch (DecoderException e) {
            throw new PersistenceException(e);
        }
        return new RuleBaseConfiguration(element.toMetadata(), element);
    }
View Full Code Here

    }

    @Test
    public void testPersistRuleBaseElement_shouldUpdateElement() throws Exception {
        RuleBaseElement element = new RuleBaseElement();
        element.setCode("code");
        element.setName("name");
        element.setPackageName("package.org");
        element.setType(RuleBaseElementType.Rule);
        RuleBaseConfiguration conf = new RuleBaseConfiguration(element);
        service.persist(conf);

        conf.getContent().setCode("new code");
        service.persist(conf);

        List<ConfigItem<RuleBaseElement>> loaded = service.load(conf.getMetaData());
        assertEquals(1, loaded.size());
        RuleBaseElement loadedElement = loaded.get(0).getContent();
        assertEquals("new code", loadedElement.getCode());
    }
View Full Code Here

        assertEquals("new code", loadedElement.getCode());
    }

    @Test
    public void testLoadRuleConfiguration_shouldFilterForType() throws Exception {
        RuleBaseElement element = new RuleBaseElement();
        element.setCode("code");
        element.setName("name");
        element.setPackageName("package.org");
        element.setType(RuleBaseElementType.Rule);
        RuleBaseConfiguration conf1 = new RuleBaseConfiguration(element);
        service.persist(conf1);

        element.setPackageName("org.openengsb");
        RuleBaseConfiguration conf2 = new RuleBaseConfiguration(element);
        service.persist(conf2);

        element.setType(RuleBaseElementType.Process);
        RuleBaseConfiguration conf3 = new RuleBaseConfiguration(element);
        service.persist(conf3);

        Map<String, String> metadata = new HashMap<String, String>();
        metadata.put(RuleBaseElement.META_RULE_TYPE, RuleBaseElementType.Rule.toString());
View Full Code Here

        assertEquals(RuleBaseElementType.Rule, loaded2.getContent().getType());
    }

    @Test
    public void testLoadRuleConfiguration_shouldLoadAll() throws Exception {
        RuleBaseElement element = new RuleBaseElement();
        element.setCode("code");
        element.setName("name");
        element.setPackageName("package.org");
        element.setType(RuleBaseElementType.Rule);
        RuleBaseConfiguration conf1 = new RuleBaseConfiguration(element);
        service.persist(conf1);

        element.setPackageName("org.openengsb");
        RuleBaseConfiguration conf2 = new RuleBaseConfiguration(element);
        service.persist(conf2);

        element.setType(RuleBaseElementType.Process);
        RuleBaseConfiguration conf3 = new RuleBaseConfiguration(element);
        service.persist(conf3);

        List<ConfigItem<RuleBaseElement>> loadedList = service.load(new HashMap<String, String>());
        assertEquals(3, loadedList.size());
View Full Code Here

        assertEquals(3, loadedList.size());
    }

    @Test
    public void testRemoveRuleConfiguration_shouldRemoveFile() throws Exception {
        RuleBaseElement element = new RuleBaseElement();
        element.setCode("code");
        element.setName("name");
        element.setPackageName("package.org");
        element.setType(RuleBaseElementType.Rule);

        RuleBaseConfiguration conf = new RuleBaseConfiguration(element);
        service.persist(conf);

        String expectedFilename =
            String.format("%s%s%s%s%s", element.getType(), separator, element.getName(), separator
                , encoder.encode(element.getPackageName()));
        File expectedTarget = new File(storageFolder, expectedFilename);
        assertTrue(expectedTarget.exists());
        service.remove(conf.getMetaData());
        assertFalse(expectedTarget.exists());
View Full Code Here

        assertEquals(0, service.load(conf.getMetaData()).size());
    }

    @Test
    public void testRemoveRuleConfiguration_shouldRemoveForMetadata() throws Exception {
        RuleBaseElement element = new RuleBaseElement();
        element.setCode("code");
        element.setName("name");
        element.setPackageName("package.org");
        element.setType(RuleBaseElementType.Rule);
        RuleBaseConfiguration conf1 = new RuleBaseConfiguration(element);
        service.persist(conf1);

        element.setPackageName("org.openengsb");
        RuleBaseConfiguration conf2 = new RuleBaseConfiguration(element);
        service.persist(conf2);

        element.setType(RuleBaseElementType.Process);
        RuleBaseConfiguration conf3 = new RuleBaseConfiguration(element);
        service.persist(conf3);

        Map<String, String> metadata = new HashMap<String, String>();
        metadata.put(RuleBaseElement.META_RULE_TYPE, RuleBaseElementType.Rule.toString());
View Full Code Here

    @Override
    public void add(RuleBaseElementId name, String code) throws RuleBaseException {
        try {
            List<RuleBaseConfiguration> existingRules =
                rulePersistence.load(new RuleBaseElement(name).toMetadata());
            if (!existingRules.isEmpty()) {
                throw new RuleBaseException("rule already exists");
            }
        } catch (PersistenceException e1) {
            throw new RuleBaseException("could not load existing rules from persistence service", e1);
        }

        RuleBaseElement objectToPersist = new RuleBaseElement(name, code);
        Map<String, String> metaData = objectToPersist.toMetadata();
        RuleBaseConfiguration conf = new RuleBaseConfiguration(metaData, objectToPersist);

        try {
            rulePersistence.persist(conf);
        } catch (PersistenceException e) {
View Full Code Here

    @Override
    public String get(RuleBaseElementId name) {
        try {
            List<RuleBaseConfiguration> existingRules =
                rulePersistence.load(new RuleBaseElement(name).toMetadata());
            if (existingRules.isEmpty()) {
                return null;
            } else {
                return existingRules.get(0).getContent().getCode();
            }
View Full Code Here

        }
    }

    @Override
    public void update(RuleBaseElementId name, String newCode) throws RuleBaseException {
        RuleBaseElement newBean = new RuleBaseElement(name, newCode);
        RuleBaseConfiguration conf = new RuleBaseConfiguration(newBean);

        try {
            rulePersistence.persist(conf);
        } catch (PersistenceException e) {
View Full Code Here

TOP

Related Classes of org.openengsb.core.workflow.drools.model.RuleBaseElement

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.