Search in sources :

Example 1 with SoftwareSystem

use of orgomg.cwm.foundation.softwaredeployment.SoftwareSystem 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)

Aggregations

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