protected Map<String, AnnotationDefinition> createTestAnnotations() { Map<String, AnnotationDefinition> annotationsDef = new HashMap<String, AnnotationDefinition>(); AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(Label.class); annotationsDef.put(annotationDefinition.getClassName(), annotationDefinition); annotationDefinition = DriverUtils.buildAnnotationDefinition(Description.class); annotationsDef.put(annotationDefinition.getClassName(), annotationDefinition); return annotationsDef; }
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( CharParamsAnnotation.class ); }
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( StringParamsAnnotation.class ); }
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( StringParamsAnnotation.class ); }
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( CharParamsAnnotation.class ); }
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( BooleanParamsAnnotation.class ); options = new ArrayList<Pair<String, String>>( ); options.add( new Pair<String, String>( "true", "true" ) ); options.add( new Pair<String, String>( "false", "false" ) ); }
@Before public void initTest() { annotationDefinition = DriverUtils.buildAnnotationDefinition( BooleanParamsAnnotation.class ); options = new ArrayList<Pair<String, String>>( ); options.add( new Pair<String, String>( "true", "true" ) ); options.add( new Pair<String, String>( "false", "false" ) ); }
public static Annotation createAnnotation(Class cls, String memberName, Object value) { AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(cls); Annotation annotation = new AnnotationImpl(annotationDefinition); if (memberName != null) { annotation.setValue(memberName, value); } return annotation; }
@Before public void init() { eventObserver = createObserver(); descriptorModel = createModel(); dataObject = new DataObjectImpl("package1", "PersistableObject"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Entity.class))); when(descriptorPath.toURI()).thenReturn(DESCRIPTOR_PATH); when(descriptorService.calculatePersistenceDescriptorPath(any(Module.class))).thenReturn(descriptorPath); when(descriptorService.load(descriptorPath)).thenReturn(descriptorModel); when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); }
@Test public void checkPlanningSolutionNoOtherExistsFirstSave() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Path dataObjectPath = mock(Path.class); when(assetsUsageService.getAssetUsages(PlanningSolution.class.getName(), ResourceType.JAVA, dataObjectPath)).thenReturn(Collections.emptyList()); Collection<ValidationMessage> result = saveValidator.validate(dataObjectPath, dataObject); assertTrue(result.isEmpty()); }
@Test public void checkPlanningSolutionNoOtherExists() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Path dataObjectPath = mock(Path.class); when(assetsUsageService.getAssetUsages(PlanningSolution.class.getName(), ResourceType.JAVA, dataObjectPath)).thenReturn(Arrays.asList(dataObjectPath)); Collection<ValidationMessage> result = saveValidator.validate(dataObjectPath, dataObject); assertTrue(result.isEmpty()); }
private DataObject createDataObject(Class<? extends Score> scoreClass) { DataObject dataObject = new DataObjectImpl("test", "Test"); if (scoreClass != null) { dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); dataObject.addProperty("score", scoreClass.getName()); } return dataObject; } }
@Test public void postProcess() { DataObject dataObject = new DataObjectImpl("test", "TestSource"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); Package _package = mock(Package.class); when(_package.getPackageMainResourcesPath()).thenReturn(PathFactory.newPath("dataObjects", "file:///dataObjects")); when(kieModuleService.resolvePackage(sourcePath)).thenReturn(_package); when(ioService.exists(any())).thenReturn(true); deleteHelper.postProcess(sourcePath); verify(ioService, times(1)).deleteIfExists(any(org.uberfire.java.nio.file.Path.class)); }
@Test public void pathValidation_dataObjectIsPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); GenerationResult generationResult = new GenerationResult(); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(1, result.size()); assertTrue(result.iterator().next() instanceof PlanningSolutionToBeDuplicatedMessage); } }
@Test public void pathValidation_noMessagesWhenGenerationFails() { GenerationResult generationResult = new GenerationResult(); generationResult.setErrors(Collections.singletonList(new DataModelerError())); DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); generationResult.setDataObject(dataObject); when(dataModelerService.loadDataObject(any(), anyString(), any())).thenReturn(generationResult); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath); assertEquals(0, result.size()); }
@Test public void checkDataObjectIsAPlanningSolution() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Collection<ValidationMessage> result = copyValidator.validate(dataObjectPath, dataObject); assertEquals(1, result.size()); ValidationMessage message = result.iterator().next(); assertTrue(message instanceof PlanningSolutionToBeDuplicatedMessage); }
public static Annotation createAnnotation(Class cls, Pair<String, Object>... valuePairs) { AnnotationDefinition annotationDefinition = DriverUtils.buildAnnotationDefinition(cls); Annotation annotation = new AnnotationImpl(annotationDefinition); for (Pair<String, Object> valuePair : valuePairs) { annotation.setValue(valuePair.getK1(), valuePair.getK2()); } return annotation; } }
@Before public void initTest() { enumOptions = new ArrayList<Pair<String, String>>(); enumOptions.add( new Pair<String, String>( TestEnums.ENUM1.VALUE1.name(), TestEnums.ENUM1.VALUE1.name() ) ); enumOptions.add( new Pair<String, String>( TestEnums.ENUM1.VALUE2.name(), TestEnums.ENUM1.VALUE2.name() ) ); enumOptions.add( new Pair<String, String>( TestEnums.ENUM1.VALUE3.name(), TestEnums.ENUM1.VALUE3.name() ) ); annotationDefinition = DriverUtils.buildAnnotationDefinition( EnumParamsAnnotation.class ); }
@Test public void extractScoreTypeFqn() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); dataObject.addProperty("score", HardSoftScore.class.getName()); String result = scoreHolderUtils.extractScoreTypeFqn(dataObject); assertEquals(HardSoftScore.class.getName(), result); } }
@Test public void validateNullProperty() { DataObject dataObject = new DataObjectImpl("test", "PlanningSolution"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); assertEquals(0, deleteValidator.validate(dataObject, null).size()); } }