Navigation Menu

Skip to content

Commit

Permalink
BZ-1275341 Jcr2vfs migration tool swaps DRL declared fact's package n…
Browse files Browse the repository at this point in the history
…ame and class name

(cherry picked from commit 402d1f4)
  • Loading branch information
wmedvede authored and csadilek committed Oct 27, 2015
1 parent 131eb0b commit 17ce25c
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 4 deletions.
Expand Up @@ -97,8 +97,8 @@ public Path importAsset( Module xmlModule, DataModelAsset xmlAsset, Path previou
DataModelAsset.DataModelObject obj = objIt.next();

// Same remark for the package as above
DataObject dataObject = new DataObjectImpl( obj.getName(),
normalizedPackageName );
DataObject dataObject = new DataObjectImpl( normalizedPackageName,
obj.getName() );
dataObject.setSuperClassName( obj.getSuperType() );

// TODO add fileOrder to object properties, and adapt kie-wb-common accordingly so that the param order in the
Expand Down Expand Up @@ -128,6 +128,7 @@ public Path importAsset( Module xmlModule, DataModelAsset xmlAsset, Path previou
if ( "Role".equals( name ) ) {
annotation = new AnnotationImpl( annotationDefinitions.get( DroolsDomainAnnotations.ROLE_ANNOTATION ) );
annotation.setValue( key, value );
dataObject.addAnnotation( annotation );
}
}

Expand Down
@@ -0,0 +1,146 @@
/*
* Copyright 2015 JBoss Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.drools.workbench.jcr2vfsmigration.vfsImport.asset;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.drools.workbench.jcr2vfsmigration.util.MigrationPathManager;
import org.drools.workbench.jcr2vfsmigration.xml.model.Module;
import org.drools.workbench.jcr2vfsmigration.xml.model.ModuleType;
import org.drools.workbench.jcr2vfsmigration.xml.model.asset.DataModelAsset;
import org.guvnor.common.services.project.service.ProjectService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.api.definition.type.Role;
import org.kie.workbench.common.screens.datamodeller.service.DataModelerService;
import org.kie.workbench.common.services.datamodeller.core.Annotation;
import org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition;
import org.kie.workbench.common.services.datamodeller.core.DataModel;
import org.kie.workbench.common.services.datamodeller.core.DataObject;
import org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl;
import org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl;
import org.kie.workbench.common.services.datamodeller.util.DriverUtils;
import org.kie.workbench.common.services.shared.project.KieProject;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.uberfire.backend.vfs.Path;
import org.uberfire.io.IOService;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class FactModelImporterTest {

@Mock
private IOService ioService;

@Mock
private MigrationPathManager migrationPathManager;

@Mock
private DataModelerService modelerService;

@Mock
private ProjectService<KieProject> projectService;

@InjectMocks
FactModelImporter factModelImporter = new FactModelImporter();

private static Map<String, AnnotationDefinition> annotationDefinitions = new HashMap<String, AnnotationDefinition>( );

static {
annotationDefinitions.put( Role.class.getName(), DriverUtils.buildAnnotationDefinition( Role.class ) );
}

@Test
public void testFactsImportGeneratedModel() {

Module xmlModule = buildModule();
DataModelAsset xmlAsset = buildDataModelAsset();

Path path = mock( Path.class );
KieProject project = mock( KieProject.class );

when( migrationPathManager.generatePathForAsset( xmlModule, xmlAsset, xmlAsset.getAssetType().toString() ) ).thenReturn( path );
when( projectService.resolveProject( path ) ).thenReturn( project );
when( modelerService.getAnnotationDefinitions() ).thenReturn( annotationDefinitions );

factModelImporter.importAsset( xmlModule, xmlAsset, null );

DataModel expectedDataModel = buildExpectedDataModel();

//The importer should create the expected data model.
verify( modelerService, times( 1 )).saveModel( eq( expectedDataModel ), eq( project ) );

}

/**
* Creates the input module for the FactModelImporter.
*/
private Module buildModule() {

Module module = new Module( ModuleType.NORMAL,
"uuid-test-module", //not relevant for the test
"test-module", //not relevant for the test
"test-user", //not relevant for the test
"last checkin comment", //not relevant for the test
new Date(), //nor relevant for the test
"org.kie.test", //At import time, the package is taken from the Module.
null, //not relevant for the test
null, //not relevant for the test
null, //not relevant for the test
null //not relevant for the test
);
return module;
}

/**
* Creates the DataModelAsset for the FactModelImporter.
*/
private DataModelAsset buildDataModelAsset() {

DataModelAsset dataModelAsset = new DataModelAsset( "TestFact", "drl", "test-user", "last checkin comment", new Date() );
DataModelAsset.DataModelObject dataModelObject = dataModelAsset.addDataModelObject( "TestFact", "java.lang.Object" );

dataModelObject.addObjectAnnotation( "Role", "value", Role.Type.EVENT.name() );
dataModelObject.addObjectProperty( "field1", "java.lang.String" );

return dataModelAsset;
}

/**
* Creates the expected result.
*/
private DataModel buildExpectedDataModel() {
DataModel dataModel = new DataModelImpl();

DataObject dataObject = dataModel.addDataObject( "org.kie.test", "TestFact" );
dataObject.setSuperClassName( "java.lang.Object" );

Annotation annotation = new AnnotationImpl( annotationDefinitions.get( Role.class.getName() ) );
annotation.setValue( "value", Role.Type.EVENT.name() );
dataObject.addAnnotation( annotation );

dataObject.addProperty( "field1", "java.lang.String" );

return dataModel;
}

}
Expand Up @@ -274,8 +274,8 @@ private void makeNewJavaTypes( final Path context,
final DataModel dataModel = new DataModelImpl();

for ( FactMetaModel factMetaModel : factModels.getModels() ) {
final DataObject dataObject = new DataObjectImpl( factMetaModel.getName(),
packageName );
final DataObject dataObject = new DataObjectImpl( packageName,
factMetaModel.getName() );
dataObject.setSuperClassName( factMetaModel.getSuperType() );
final List<AnnotationMetaModel> annotationMetaModel = factMetaModel.getAnnotations();
addAnnotations( dataObject,
Expand Down

0 comments on commit 17ce25c

Please sign in to comment.