List<Installation> envVars = new ArrayList<Installation>( 2 );
envVars.add( firstEnvVar );
envVars.add( secondEnvVar );
Profile firstProfile = createTestProfile( "first", "", 1, true, true, testOne, testTwo, envVars );
Profile secondProfile = createTestProfile( "first", "", 1, true, true, testOne, testTwo, envVars );
firstProfile = profileDao.addProfile( firstProfile );
secondProfile = profileDao.addProfile( secondProfile );
Profile firstGetted = profileDao.getProfile( firstProfile.getId() );
Profile secondGetted = profileDao.getProfile( secondProfile.getId() );
assertNotNull( firstGetted );
assertNotNull( firstGetted.getJdk() );
assertEquals( nameFirstInst, firstGetted.getJdk().getName() );
assertNotNull( secondGetted );
assertNotNull( secondGetted.getJdk() );
assertEquals( nameFirstInst, secondGetted.getJdk().getName() );
assertNotNull( firstGetted.getBuilder() );
assertEquals( nameSecondInst, firstGetted.getBuilder().getName() );
assertEquals( 2, firstGetted.getEnvironmentVariables().size() );
assertNotNull( secondGetted.getBuilder() );
assertEquals( nameSecondInst, secondGetted.getBuilder().getName() );
assertEquals( 2, secondGetted.getEnvironmentVariables().size() );
installationDao.removeInstallation( testOne );
Installation fromStore = installationDao.getInstallation( testOne.getInstallationId() );
assertNull( fromStore );
firstGetted = profileDao.getProfile( firstProfile.getId() );
secondGetted = profileDao.getProfile( secondProfile.getId() );
assertNotNull( firstGetted );
assertNull( firstGetted.getJdk() );
assertNotNull( firstGetted.getBuilder() );
assertEquals( 2, firstGetted.getEnvironmentVariables().size() );
assertNotNull( secondGetted );
assertNull( secondGetted.getJdk() );
assertNotNull( secondGetted.getBuilder() );
assertEquals( 2, secondGetted.getEnvironmentVariables().size() );
// removing builder
installationDao.removeInstallation( testTwo );
firstGetted = profileDao.getProfile( firstProfile.getId() );
secondGetted = profileDao.getProfile( secondProfile.getId() );
assertNotNull( firstGetted );
assertNull( firstGetted.getJdk() );
assertNull( firstGetted.getBuilder() );
assertEquals( 2, firstGetted.getEnvironmentVariables().size() );
assertNotNull( secondGetted );
assertNull( secondGetted.getJdk() );
assertNull( secondGetted.getBuilder() );
assertEquals( 2, secondGetted.getEnvironmentVariables().size() );
// removing firstEnvVar
installationDao.removeInstallation( firstEnvVar );
firstGetted = profileDao.getProfile( firstProfile.getId() );
secondGetted = profileDao.getProfile( secondProfile.getId() );
assertNotNull( firstGetted );
assertNull( firstGetted.getJdk() );
assertNull( firstGetted.getBuilder() );
assertEquals( 1, firstGetted.getEnvironmentVariables().size() );
Installation env = (Installation) firstGetted.getEnvironmentVariables().get( 0 );
assertEquals( nameSecondEnvVar, env.getName() );
assertNotNull( secondGetted );
assertNull( secondGetted.getJdk() );
assertNull( secondGetted.getBuilder() );
assertEquals( 1, secondGetted.getEnvironmentVariables().size() );
env = (Installation) secondGetted.getEnvironmentVariables().get( 0 );
assertEquals( nameSecondEnvVar, env.getName() );
// removing secondEnvVar
installationDao.removeInstallation( secondEnvVar );
firstGetted = profileDao.getProfile( firstProfile.getId() );
secondGetted = profileDao.getProfile( secondProfile.getId() );
assertNotNull( firstGetted );
assertNull( firstGetted.getJdk() );
assertNull( firstGetted.getBuilder() );
assertEquals( 0, firstGetted.getEnvironmentVariables().size() );
assertNotNull( secondGetted );
assertNull( secondGetted.getJdk() );
assertNull( secondGetted.getBuilder() );
assertEquals( 0, secondGetted.getEnvironmentVariables().size() );
}