use of org.talend.dq.writer.EMFSharedResources in project tdq-studio-se by Talend.
the class SoftwareSystemManagerTest method testUpdateSoftwareSystem.
/**
* Test method for
* {@link org.talend.cwm.management.api.SoftwareSystemManager#updateSoftwareSystem(java.sql.Connection, orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)}
* .
*/
@Test
public void testUpdateSoftwareSystem() {
SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
PowerMockito.mockStatic(EMFSharedResources.class);
EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
Resource softwareSysResource = mock(Resource.class);
when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
EList<EObject> existedSystems = new BasicEList<EObject>();
when(softwareSysResource.getContents()).thenReturn(existedSystems);
when(emfSharedResourceMock.saveResource(softwareSysResource)).thenReturn(Boolean.TRUE);
try {
softwareSystemManger.updateSoftwareSystem(null);
Connection mockConnection = mock(Connection.class);
DatabaseMetaData mockDBMetaData = mock(DatabaseMetaData.class);
// Mocking Static Class
PowerMockito.mockStatic(DriverManager.class);
// $NON-NLS-1$
String sql = "jdbc:mysql://localhost:3306/tbi";
when(DriverManager.getConnection(sql)).thenReturn(mockConnection);
when(mockConnection.getMetaData()).thenReturn(mockDBMetaData);
// Mock database product name.
// $NON-NLS-1$
String mysqlDB = "MYSQL";
when(mockDBMetaData.getDatabaseProductName()).thenReturn(mysqlDB);
// Mock database product version
// $NON-NLS-1$
String version = "5.5";
when(mockDBMetaData.getDatabaseProductVersion()).thenReturn(version);
when(mockDBMetaData.getDatabaseMinorVersion()).thenReturn(5);
when(mockDBMetaData.getDatabaseMajorVersion()).thenReturn(5);
DatabaseConnection dbConn = ConnectionPackage.eINSTANCE.getConnectionFactory().createDatabaseConnection();
TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_NAME, mysqlDB);
TaggedValueHelper.setTaggedValue(dbConn, TaggedValueHelper.DB_PRODUCT_VERSION, version);
PowerMockito.mockStatic(ConvertionHelper.class);
// $NON-NLS-1$
when(ConvertionHelper.convert(dbConn, false, "")).thenReturn(null);
PowerMockito.mockStatic(MetadataFillFactory.class);
MetadataFillFactory metadataFillFactory = mock(MetadataFillFactory.class);
when(MetadataFillFactory.getDBInstance()).thenReturn(metadataFillFactory);
TypedReturnCode<java.sql.Connection> returnCode = new TypedReturnCode<Connection>(Boolean.TRUE);
returnCode.setObject(mockConnection);
when(metadataFillFactory.createConnection(null)).thenReturn(returnCode);
softwareSystemManger.updateSoftwareSystem(dbConn);
Assert.assertTrue(existedSystems.size() > 0);
SoftwareSystem newSoftwareSys = (SoftwareSystem) existedSystems.get(0);
Assert.assertEquals(mysqlDB, newSoftwareSys.getSubtype());
Assert.assertEquals(version, newSoftwareSys.getVersion());
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}
use of org.talend.dq.writer.EMFSharedResources in project tdq-studio-se by Talend.
the class SoftwareSystemManagerTest method testGetNewDBTypes.
@Test
public void testGetNewDBTypes() {
SoftwareSystemManager softwareSystemManger = SoftwareSystemManager.getInstance();
Set<String> existingTypes = new HashSet<String>();
// $NON-NLS-1$
existingTypes.add("MYSQL");
// $NON-NLS-1$
existingTypes.add("oracle");
PowerMockito.mockStatic(EMFSharedResources.class);
EMFSharedResources emfSharedResourceMock = mock(EMFSharedResources.class);
when(EMFSharedResources.getInstance()).thenReturn(emfSharedResourceMock).thenReturn(emfSharedResourceMock);
Resource softwareSysResource = mock(Resource.class);
when(emfSharedResourceMock.getSoftwareDeploymentResource()).thenReturn(softwareSysResource);
EList<EObject> existedSystems = new BasicEList<EObject>();
TdSoftwareSystem softwareSystem1 = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
// $NON-NLS-1$
softwareSystem1.setSubtype("mysql");
TdSoftwareSystem softwareSystem2 = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
// $NON-NLS-1$
softwareSystem2.setSubtype("VERTICA");
TdSoftwareSystem softwareSystem3 = SoftwaredeploymentPackage.eINSTANCE.getSoftwaredeploymentFactory().createTdSoftwareSystem();
// $NON-NLS-1$
softwareSystem3.setSubtype("Oracle");
existedSystems.add(softwareSystem1);
existedSystems.add(softwareSystem2);
existedSystems.add(softwareSystem3);
when(softwareSysResource.getContents()).thenReturn(existedSystems);
List<String> newTypes = softwareSystemManger.getNewDBTypesFromSoftwareSystem(existingTypes);
Assert.assertEquals(1, newTypes.size());
// $NON-NLS-1$
Assert.assertEquals("VERTICA", newTypes.get(0));
}
Aggregations