agave-apps/apps-core/src/test/java/org/iplantc/service/apps/managers/ApplicationManagerIT.java
/**
	 * Tests that an application is semantically identical before and after update.
	 * @throws Exception 
	 */
Tests that an application is semantically identical before and after update.
@throws Exception
Tests that an application is semantically identical before and after update . @throws Exception
@Test
	public void processSoftwareUpdatesExistingSoftware() 
	throws Exception
	{
		try {
			Software oldSoftware = createSoftware();
			JSONObject json = JSONTestDataUtil.getInstance().getTestDataObject(TEST_SOFTWARE_SYSTEM_FILE);
			json.put("name", oldSoftware.getName());
			json.put("version", oldSoftware.getVersion());
			json.put("executionSystem", oldSoftware.getExecutionSystem().getSystemId());
			json.put("deploymentSystem", oldSoftware.getStorageSystem().getSystemId());
			ApplicationManager manager = Mockito.spy(new ApplicationManager());
			Mockito.doReturn(Boolean.TRUE)
					.when(manager)
					.validateSoftwareDependencies(Mockito.any(String.class), Mockito.any(Software.class));
			Software newSoftware = manager.processSoftware(oldSoftware, json, oldSoftware.getOwner());
			Assert.assertEquals(newSoftware.getUuid(), oldSoftware.getUuid(),
					"UUID should be the same before and after processing");
			Assert.assertEquals(newSoftware.getCreated().toString(), oldSoftware.getCreated().toString(),
					"created timestamp should be the same before and after processing");
			Assert.assertTrue(newSoftware.getLastUpdated().after(oldSoftware.getLastUpdated()),
					"lastUpdated timestamp should not be equal before and after processing");
			Assert.assertEquals(newSoftware.getRevisionCount().intValue(),
					oldSoftware.getRevisionCount() + 1,
					"revision count was not incremented on update");
			for (SoftwarePermission oldPem : oldSoftware.getPermissions()) {
				Assert.assertTrue(newSoftware.getPermissions().contains(oldPem),
						"All permissions should be carried over after processing.");
			}
			SoftwareDao.replace(oldSoftware, newSoftware);
			Software oldSoftwareResult = SoftwareDao.get(oldSoftware.getId());
			Software newSoftwareResult = SoftwareDao.get(newSoftware.getId());
			Assert.assertNull(oldSoftwareResult,
					"Search for old software by id should return null.");
			Assert.assertNotNull(newSoftwareResult,
					"Search for new software by id should return new software.");
			newSoftwareResult = SoftwareDao.getSoftwareByUniqueName(newSoftwareResult.getUniqueName());
			Assert.assertNotNull(newSoftwareResult,
					"Search for new software by unique name should return new software.");
			List<Software> nameResults =
					SoftwareDao.getByName(newSoftware.getName(), false, true);
			Assert.assertEquals(nameResults.size(), 1,
					"Search for new software by name should return only the new software object.");
			Assert.assertNotNull(newSoftwareResult,
					"Search for new software by id should return new software.");
			for (SoftwarePermission oldPem : oldSoftware.getPermissions()) {
				Assert.assertTrue(newSoftwareResult.getPermissions().contains(oldPem),
						"All permissions should be carried over after processing.");
			}
		}
		catch (JSONException | IOException e) {
			Assert.fail("No exception should be thrown updating a valid app with a new one.", e);
		}
	}
@ Test public void processSoftwareUpdatesExistingSoftware ( ) throws Exception { try { Software oldSoftware = createSoftware ( ) ; JSONObject json = JSONTestDataUtil . getInstance ( ) . getTestDataObject ( TEST_SOFTWARE_SYSTEM_FILE ) ; json . put ( "name" , oldSoftware . getName ( ) ) ; json . put ( "version" , oldSoftware . getVersion ( ) ) ; json . put ( "executionSystem" , oldSoftware . getExecutionSystem ( ) . getSystemId ( ) ) ; json . put ( "deploymentSystem" , oldSoftware . getStorageSystem ( ) . getSystemId ( ) ) ; ApplicationManager manager = Mockito . spy ( new ApplicationManager ( ) ) ; Mockito . doReturn ( Boolean . TRUE ) . when ( manager ) . validateSoftwareDependencies ( Mockito . any ( String . class ) , Mockito . any ( Software . class ) ) ; Software newSoftware = manager . processSoftware ( oldSoftware , json , oldSoftware . getOwner ( ) ) ; Assert . assertEquals ( newSoftware . getUuid ( ) , oldSoftware . getUuid ( ) , "UUID should be the same before and after processing" ) ; Assert . assertEquals ( newSoftware . getCreated ( ) . toString ( ) , oldSoftware . getCreated ( ) . toString ( ) , "created timestamp should be the same before and after processing" ) ; Assert . assertTrue ( newSoftware . getLastUpdated ( ) . after ( oldSoftware . getLastUpdated ( ) ) , "lastUpdated timestamp should not be equal before and after processing" ) ; Assert . assertEquals ( newSoftware . getRevisionCount ( ) . intValue ( ) , oldSoftware . getRevisionCount ( ) + 1 , "revision count was not incremented on update" ) ; for ( SoftwarePermission oldPem : oldSoftware . getPermissions ( ) ) { Assert . assertTrue ( newSoftware . getPermissions ( ) . contains ( oldPem ) , "All permissions should be carried over after processing." ) ; } SoftwareDao . replace ( oldSoftware , newSoftware ) ; Software oldSoftwareResult = SoftwareDao . get ( oldSoftware . getId ( ) ) ; Software newSoftwareResult = SoftwareDao . get ( newSoftware . getId ( ) ) ; Assert . assertNull ( oldSoftwareResult , "Search for old software by id should return null." ) ; Assert . assertNotNull ( newSoftwareResult , "Search for new software by id should return new software." ) ; newSoftwareResult = SoftwareDao . getSoftwareByUniqueName ( newSoftwareResult . getUniqueName ( ) ) ; Assert . assertNotNull ( newSoftwareResult , "Search for new software by unique name should return new software." ) ; List < Software > nameResults = SoftwareDao . getByName ( newSoftware . getName ( ) , false , true ) ; Assert . assertEquals ( nameResults . size ( ) , 1 , "Search for new software by name should return only the new software object." ) ; Assert . assertNotNull ( newSoftwareResult , "Search for new software by id should return new software." ) ; for ( SoftwarePermission oldPem : oldSoftware . getPermissions ( ) ) { Assert . assertTrue ( newSoftwareResult . getPermissions ( ) . contains ( oldPem ) , "All permissions should be carried over after processing." ) ; } } catch ( JSONException | IOException e ) { Assert . fail ( "No exception should be thrown updating a valid app with a new one." , e ) ; } }
Tests that an application is semantically identical before and after update.
Tests that an application is semantically identical before and after update .
// search for new and old software objects