public Annotation createAnnotation( Map<String, AnnotationDefinition> systemAnnotations, String className, String memberName, Object value ) { AnnotationDefinition annotationDefinition = systemAnnotations.get( className ); Annotation annotation = new AnnotationImpl( annotationDefinition ); if ( memberName != null ) { annotation.setValue( memberName, value ); } return annotation; } }
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); }
@Override public Annotation buildAnnotation(AnnotationDefinition annotationDefinition, Object annotationToken) throws ModelDriverException { org.kie.soup.project.datamodel.oracle.Annotation oracleAnnotationToken = (org.kie.soup.project.datamodel.oracle.Annotation)annotationToken; AnnotationImpl annotation = new AnnotationImpl(annotationDefinition); if (annotationDefinition.isMarker()) { return annotation; } else if (oracleAnnotationToken.getParameters() != null) { Object currentAttributeValue; for (AnnotationValuePairDefinition annotationMember : annotationDefinition.getValuePairs()) { currentAttributeValue = oracleAnnotationToken.getParameters().get(annotationMember.getName()); if (currentAttributeValue != null) { annotation.setValue(annotationMember.getName(), currentAttributeValue); } } } return annotation; } }
@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()); }
@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 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); copyHelper.postProcess(sourcePath, destinationPath); verify(ioService, times(1)).copy(any(org.uberfire.java.nio.file.Path.class), any(org.uberfire.java.nio.file.Path.class)); }
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)); }
@Override public Annotation buildAnnotation( AnnotationDefinition annotationDefinition, Object annotationToken ) throws ModelDriverException { AnnotationSource javaAnnotationToken = ( AnnotationSource ) annotationToken; AnnotationImpl annotation = new AnnotationImpl( annotationDefinition ); if ( annotationDefinition.isMarker() ) { return annotation; } else { if ( javaAnnotationToken.getValues() != null ) { List<ValuePair> values = javaAnnotationToken.getValues(); if ( values != null && values.size() > 0 ) { for ( AnnotationValuePairDefinition valuePairDefinition : annotationDefinition.getValuePairs() ) { Object annotationValue = buildAnnotationValue( javaAnnotationToken, valuePairDefinition ); if ( annotationValue != null ) { annotation.setValue( valuePairDefinition.getName(), annotationValue ); } } } } } return annotation; }
@Test public void checkPlanningSolutionOtherExists() { DataObject dataObject = new DataObjectImpl("test", "Test"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); Path dataObjectPath = mock(Path.class); Path otherDataObjectPath = mock(Path.class); when(assetsUsageService.getAssetUsages(PlanningSolution.class.getName(), ResourceType.JAVA, dataObjectPath)).thenReturn(Arrays.asList(otherDataObjectPath)); Collection<ValidationMessage> result = saveValidator.validate(dataObjectPath, dataObject); assertEquals(1, result.size()); ValidationMessage message = result.iterator().next(); assertTrue(message instanceof PlanningSolutionToBeDuplicatedMessage); } }
@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); renameHelper.postProcess(sourcePath, destinationPath); verify(ioService, times(1)).move(any(org.uberfire.java.nio.file.Path.class), 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 validateIsAPlanningScore() { DataObject dataObject = new DataObjectImpl("test", "PlanningSolution"); dataObject.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningSolution.class))); ObjectProperty objectProperty = new ObjectPropertyImpl("score", HardSoftScore.class.getName(), false); objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(PlanningScore.class))); objectProperty.addAnnotation(new AnnotationImpl(DriverUtils.buildAnnotationDefinition(Generated.class))); Collection<ValidationMessage> result = deleteValidator.validate(dataObject, objectProperty); assertEquals(1, result.size()); assertTrue(result.iterator().next() instanceof PlanningScoreToBeDeletedMessage); }
@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); }
@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()); }
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; } }
@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()); } }
protected ObjectProperty addProperty(DataObject dataObject, String propertyName, String className, boolean multiple, boolean withLabels) { ObjectProperty property = dataObject.addProperty(propertyName, className, multiple); if (withLabels) { Annotation labelAnnotation = new AnnotationImpl(new AnnotationDefinitionImpl(MainDomainAnnotations.LABEL_ANNOTATION)); labelAnnotation.setValue(MainDomainAnnotations.VALUE_PARAM, LABEL_SUFFIX + propertyName); property.addAnnotation(labelAnnotation); } return property; } }