Search in sources :

Example 1 with EMFSharedResources

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());
    }
}
Also used : SQLException(java.sql.SQLException) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Connection(java.sql.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseMetaData(java.sql.DatabaseMetaData) EMFSharedResources(org.talend.dq.writer.EMFSharedResources) EObject(org.eclipse.emf.ecore.EObject) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) SoftwareSystem(orgomg.cwm.foundation.softwaredeployment.SoftwareSystem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with EMFSharedResources

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));
}
Also used : EMFSharedResources(org.talend.dq.writer.EMFSharedResources) EObject(org.eclipse.emf.ecore.EObject) BasicEList(org.eclipse.emf.common.util.BasicEList) TdSoftwareSystem(org.talend.cwm.softwaredeployment.TdSoftwareSystem) Resource(org.eclipse.emf.ecore.resource.Resource) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

BasicEList (org.eclipse.emf.common.util.BasicEList)2 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 TdSoftwareSystem (org.talend.cwm.softwaredeployment.TdSoftwareSystem)2 EMFSharedResources (org.talend.dq.writer.EMFSharedResources)2 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 MetadataFillFactory (org.talend.metadata.managment.model.MetadataFillFactory)1 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)1 SoftwareSystem (orgomg.cwm.foundation.softwaredeployment.SoftwareSystem)1