Java Code Examples for org.junit.Rule

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project openengsb-framework, under directory /components/workflow/src/test/java/org/openengsb/core/workflow/drools/deployer/.

Source file: WorkflowDeployerServiceTest.java

  30 
vote

@Test public void testWorkflowDeployerService_shouldInstallArtifacts() throws Exception {
  File ruleFile=readExampleRuleFile();
  File processFile=readExampleProcessFile();
  workflowDeployer.install(ruleFile);
  workflowDeployer.install(processFile);
  RuleBaseElementId idRule=new RuleBaseElementId(RuleBaseElementType.Rule,"org.openengsb","rule");
  RuleBaseElementId idProcess=new RuleBaseElementId(RuleBaseElementType.Process,"org.openengsb","process");
  verify(ruleManager,times(1)).addOrUpdate(idRule,FileUtils.readFileToString(ruleFile));
  verify(ruleManager,times(1)).addOrUpdate(idProcess,FileUtils.readFileToString(processFile));
}
 

Example 2

From project openengsb-framework, under directory /components/workflow/src/test/java/org/openengsb/core/workflow/drools/deployer/.

Source file: WorkflowDeployerServiceTest.java

  29 
vote

@Test public void testWorkflowDeployerService_shouldUpdateArtifacts() throws Exception {
  File ruleFile=readExampleRuleFile();
  File processFile=readExampleProcessFile();
  workflowDeployer.install(ruleFile);
  workflowDeployer.install(processFile);
  String modifiedRule="it doesnt matter";
  FileUtils.writeStringToFile(ruleFile,modifiedRule);
  RuleBaseElementId idRule=new RuleBaseElementId(RuleBaseElementType.Rule,"org.openengsb","rule");
  workflowDeployer.update(ruleFile);
  verify(ruleManager,times(1)).addOrUpdate(idRule,modifiedRule);
  String process=FileUtils.readFileToString(processFile);
  String modifiedProcess=process.replace("org.openengsb","new.package");
  FileUtils.writeStringToFile(processFile,modifiedProcess);
  workflowDeployer.update(processFile);
  RuleBaseElementId idProcess=new RuleBaseElementId(RuleBaseElementType.Process,"org.openengsb","process");
  verify(ruleManager,times(1)).delete(idProcess);
  idProcess.setPackageName("new.package");
  verify(ruleManager,times(1)).addOrUpdate(idProcess,modifiedProcess);
}
 

Example 3

From project openengsb-framework, under directory /components/workflow/src/test/java/org/openengsb/core/workflow/drools/deployer/.

Source file: WorkflowDeployerServiceTest.java

  29 
vote

@Test public void testWorkflowDeployerService_shouldDeleteArtifacts() throws Exception {
  File ruleFile=readExampleRuleFile();
  File processFile=readExampleProcessFile();
  workflowDeployer.install(ruleFile);
  workflowDeployer.install(processFile);
  workflowDeployer.uninstall(ruleFile);
  workflowDeployer.uninstall(processFile);
  RuleBaseElementId idRule=new RuleBaseElementId(RuleBaseElementType.Rule,"org.openengsb","rule");
  RuleBaseElementId idProcess=new RuleBaseElementId(RuleBaseElementType.Process,"org.openengsb","process");
  verify(ruleManager,times(1)).delete(idRule);
  verify(ruleManager,times(1)).delete(idProcess);
}
 

Example 4

From project openengsb-framework, under directory /components/workflow/src/test/java/org/openengsb/core/workflow/drools/deployer/.

Source file: WorkflowDeployerServiceTest.java

  29 
vote

@Test public void testInstallWrongOrder_shouldAttemptInstallAgain() throws Exception {
  setupWithRealCompiler();
  final File importFile=temporaryFolder.newFile("test1.import");
  FileUtils.writeLines(importFile,Arrays.asList(Event.class.getName(),BigInteger.class.getName(),Logger.class.getName(),""));
  final File globalFile=temporaryFolder.newFile("test1.global");
  FileUtils.writeLines(globalFile,Arrays.asList(List.class.getName() + " listtest",Logger.class.getSimpleName() + " logger",""));
  final File testRuleFile=temporaryFolder.newFile("test1.rule");
  FileUtils.writeLines(testRuleFile,Arrays.asList("when","   Event()","then","   BigInteger i = new BigInteger(1);","   logger.info(i.toString());",""));
  workflowDeployer.install(testRuleFile);
  workflowDeployer.install(globalFile);
  workflowDeployer.install(importFile);
  assertThat(ruleManager.get(new RuleBaseElementId(RuleBaseElementType.Rule,"test1")),not(nullValue()));
}
 

Example 5

From project openengsb-framework, under directory /persistence/rulebase/src/test/java/org/openengsb/persistence/rulebase/filebackend/.

Source file: RuleBaseElementPersistenceBackendServiceTest.java

  29 
vote

@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());
}
 

Example 6

From project openengsb-framework, under directory /persistence/rulebase/src/test/java/org/openengsb/persistence/rulebase/filebackend/.

Source file: RuleBaseElementPersistenceBackendServiceTest.java

  29 
vote

@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());
}
 

Example 7

From project openengsb-framework, under directory /persistence/rulebase/src/test/java/org/openengsb/persistence/rulebase/filebackend/.

Source file: RuleBaseElementPersistenceBackendServiceTest.java

  29 
vote

@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());
  List<ConfigItem<RuleBaseElement>> loadedList=service.load(metadata);
  assertEquals(2,loadedList.size());
  RuleBaseConfiguration loaded1=(RuleBaseConfiguration)loadedList.get(0);
  RuleBaseConfiguration loaded2=(RuleBaseConfiguration)loadedList.get(1);
  assertEquals(RuleBaseElementType.Rule,loaded1.getContent().getType());
  assertEquals(RuleBaseElementType.Rule,loaded2.getContent().getType());
}
 

Example 8

From project openengsb-framework, under directory /persistence/rulebase/src/test/java/org/openengsb/persistence/rulebase/filebackend/.

Source file: RuleBaseElementPersistenceBackendServiceTest.java

  29 
vote

@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());
}
 

Example 9

From project openengsb-framework, under directory /persistence/rulebase/src/test/java/org/openengsb/persistence/rulebase/filebackend/.

Source file: RuleBaseElementPersistenceBackendServiceTest.java

  29 
vote

@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());
  assertEquals(0,service.load(conf.getMetaData()).size());
}
 

Example 10

From project openengsb-framework, under directory /persistence/rulebase/src/test/java/org/openengsb/persistence/rulebase/filebackend/.

Source file: RuleBaseElementPersistenceBackendServiceTest.java

  29 
vote

@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());
  service.remove(metadata);
  List<ConfigItem<RuleBaseElement>> remainingList=service.load(new HashMap<String,String>());
  assertEquals(1,remainingList.size());
  RuleBaseConfiguration remainingElement=(RuleBaseConfiguration)remainingList.get(0);
  assertEquals(RuleBaseElementType.Process,remainingElement.getContent().getType());
}