use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AddModifyApplicationBackingTest method testCreateAndModifyApplications.
@Test
public void testCreateAndModifyApplications() {
ModelTestUtils.resetTestDb();
ModelTestUtils.createModel(null);
ModelManager mm = ModelTestUtils.createModelManager();
//////////////////////////
// Verify that we can use the backing to create a new application
Map<Object, Object> vars = new HashMap<Object, Object>();
Map<Object, Object> parms = new HashMap<Object, Object>();
AddModifyApplicationBacking amab = null;
parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APP });
parms.put(FormConstants.APP_ID, new String[] {});
parms.put("name", new String[] { "Application.name.3" });
parms.put(FormConstants.APP_DESCRIPTION, new String[] { "Application.description.3" });
parms.put("deviceTypes", new String[] { "1" });
amab = new AddModifyApplicationBacking();
amab.setModelManager(mm);
amab.process(null, vars, parms);
Assert.assertTrue(vars.get(FormConstants.PROCESS_TARGET) != null && ((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APP) == 0);
Assert.assertTrue(vars.get("application") != null && ((Application) vars.get("application")).getName().compareTo("Application.name.3") == 0);
//////////////////////////
// Verify that inadequate data will throw an exception
// and that exception will manifest as an event returned
// that targets the message backing.
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APP });
parms.put(FormConstants.APP_ID, new String[] {});
parms.put(FormConstants.APP_DESCRIPTION, new String[] { "Application.description.4" });
parms.put("deviceTypes", new String[] { "1" });
amab = new AddModifyApplicationBacking();
amab.setModelManager(mm);
Collection<ProcessingEvent> events = amab.process(null, vars, parms);
Assert.assertTrue(events.size() > 0);
Integer numFound = 0;
for (ProcessingEvent event : events) {
if (event.getTargets()[0].compareTo(ProcessingTargets.MESSAGES) == 0) {
numFound++;
}
}
Assert.assertTrue(numFound == 1);
//////////////////////////
// Verify that we can use the backing to modify an application
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APP });
// we happen to know that the model creates an application with id 1 that is not named Application.name.3
parms.put(FormConstants.APP_ID, new String[] { "1" });
parms.put("name", new String[] { "Application.name.1" });
parms.put(FormConstants.APP_DESCRIPTION, new String[] { "Application.description.1_modified" });
parms.put("deviceTypes", new String[] { "1", "2" });
amab = new AddModifyApplicationBacking();
amab.setModelManager(mm);
amab.process(null, vars, parms);
Assert.assertTrue(vars.get(FormConstants.PROCESS_TARGET) != null && ((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APP) == 0);
Assert.assertTrue(vars.get("application") != null && ((Application) vars.get("application")).getDescription().compareTo("Application.description.1_modified") == 0);
// verify that the applicaiton we modified is otherwise uncorrupted.
Application app = mm.getModelService().findByPrimaryKey(Application.class, 1L);
Assert.assertTrue(app.getName() != null && app.getName().compareTo("Application.name.1") == 0);
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AddModifyApplicationVersionsBackingTest method testFormSetup.
@Test
public void testFormSetup() {
ModelManager mm = modelManager;
//////////////////
// Verify the correct templateVariables are produced when no applicationId is passed in
// You cannot modify an app version without an application, so there will be a minimal return
Map<Object, Object> vars = new HashMap<Object, Object>();
Map<Object, Object> parms = new HashMap<Object, Object>();
AddModifyApplicationVersionBacking amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(mm);
Collection<ProcessingEvent> events = amab.process(null, vars, parms);
Assert.assertTrue(events.size() == 1 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
Assert.assertTrue(vars.size() == 1 && vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
///////////////////////
// verify the correct templateVariables are produced with an invalid applcationId is passed
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.APP_ID, new String[] { "666" });
amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(mm);
events = amab.process(null, vars, parms);
Assert.assertTrue(events.size() == 1 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
Assert.assertTrue(vars.size() == 1 && vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
/////////////////////
// verify the correct templateVariables are produced with an valid applcationId,
// but invalid versionId is passed
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.APP_ID, new String[] { "1" });
parms.put("versionId", new String[] { "666" });
amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(mm);
events = amab.process(null, vars, parms);
Assert.assertTrue(events.size() == 4 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
Assert.assertTrue(vars.size() == 6);
Assert.assertTrue(vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
Assert.assertTrue(vars.get("application") != null && ((Application) vars.get("application")).getName().compareTo("Application.name") == 0);
Assert.assertTrue(vars.get("version") != null && ((ApplicationVersion) vars.get("version")).getIdentifier() == null);
Assert.assertTrue(vars.get("hashTypes") != null && ((List) vars.get("hashTypes")).size() == HashAlgorithm.values().length);
Assert.assertTrue(((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APPVER) == 0);
//////////////////////
// verify the correct templateVariables are produced when
// both a valid app id and version id are passed in
vars = new HashMap<Object, Object>();
parms = new HashMap<Object, Object>();
parms.put(FormConstants.APP_ID, new String[] { "1" });
parms.put("versionId", new String[] { "1" });
amab = new AddModifyApplicationVersionBacking();
amab.setModelManager(mm);
events = amab.process(null, vars, parms);
Assert.assertTrue(events.size() == 3);
Assert.assertTrue(vars.size() == 6);
Assert.assertTrue(vars.get(FormConstants.ENCODING_TYPE).equals("enctype=\"" + FormConstants.ENCTYPE_MULTIPART_FORMDATA + "\""));
Assert.assertTrue(vars.get("application") != null && ((Application) vars.get("application")).getName().compareTo("Application.name") == 0);
Assert.assertTrue(vars.get("version") != null && ((ApplicationVersion) vars.get("version")).getIdentifier().compareTo("ApplicationVersion.identifier.1") == 0);
Assert.assertTrue(vars.get("hashTypes") != null && ((List) vars.get("hashTypes")).size() == HashAlgorithm.values().length);
Assert.assertTrue(((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APPVER) == 0);
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServiceImpl method getApplication.
/*
* PRIVATE METHODS
*/
private Application getApplication(String appName, String appVersionId) throws WebServiceException {
if (appName == null || appVersionId == null) {
throw new WebServiceException(WebServiceException.TypeEnum.APPLICATION_VERSION_NOTFOUND, "Both application name and version id must be specified.");
}
ModelManager manager = getModelManager();
// we will need to verify that they have the latest version
Application application = manager.getModelService().findApplicationByName(appName);
if (application == null) {
throw new WebServiceException(WebServiceException.TypeEnum.APPLICATION_NOTFOUND, "The application \"" + appName + "\" was not found.");
}
return application;
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ApplicationManagementPortTypeImplTest method testConnectionOpen_verifyInitialVersionIdentifierRecognized.
/**
* Verify that no exceptions are thrown and no update returned
* when the version SLIC reports is the same as the initial version.
*/
@Test
public void testConnectionOpen_verifyInitialVersionIdentifierRecognized() throws Exception {
thrown = false;
request.getApplication().setVersionId("ApplicationVersion.identifier.bundled");
com.openmeap.model.dto.Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
Iterator<Deployment> i = new ArrayList<Deployment>(app.getDeployments()).iterator();
try {
modelManager.begin();
while (i.hasNext()) {
Deployment d = i.next();
modelManager.delete(d, null);
}
modelManager.commit();
} catch (Exception e) {
modelManager.rollback();
throw new Exception(e);
}
try {
response = appMgmtSvc.connectionOpen(request);
} catch (WebServiceException wse) {
thrown = true;
}
Assert.assertTrue("No update should be returned here", response.getUpdate() == null);
Assert.assertTrue("The originally bundled application version id should not trigger an exception", thrown == false);
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ModelServiceRefreshNotifier method makeRequest.
/**
* This MUST remain state-less
*
* @param <T>
* @param thisUrl
* @param obj
*/
@Override
protected void makeRequest(final URL url, final Event<ModelEntity> mesg) throws ClusterNotificationException {
com.openmeap.http.HttpResponse httpResponse = null;
String simpleName = null;
String thisUrl = url.toString() + "/" + ServletNameConstants.SERVICE_MANAGEMENT + "/";
ModelEntity obj = mesg.getPayload();
// I am not using obj.getClass().getSimpleName() because of Hibernate Proxy object wrapping
if (obj instanceof Application)
simpleName = "Application";
else if (obj instanceof ApplicationVersion)
simpleName = "ApplicationVersion";
else if (obj instanceof ApplicationArchive)
simpleName = "ApplicationArchive";
else if (obj instanceof ApplicationInstallation)
simpleName = "ApplicationInstallation";
else if (obj instanceof GlobalSettings)
simpleName = "GlobalSettings";
else
return;
Hashtable<String, Object> parms = new Hashtable<String, Object>();
parms.put(UrlParamConstants.ACTION, ModelEntityEventAction.MODEL_REFRESH.getActionName());
parms.put(UrlParamConstants.AUTH_TOKEN, newAuthToken());
parms.put(UrlParamConstants.REFRESH_TYPE, simpleName);
parms.put(UrlParamConstants.REFRESH_OBJ_PKID, obj.getPk());
try {
logger.debug("Refresh post to {} for {} with id {}", new Object[] { thisUrl, simpleName, obj.getPk() });
httpResponse = getHttpRequestExecuter().postData(thisUrl, parms);
Utils.consumeInputStream(httpResponse.getResponseBody());
int statusCode = httpResponse.getStatusCode();
if (statusCode != 200) {
String exMesg = "HTTP " + statusCode + " returned for refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk();
logger.error(exMesg);
throw new ClusterNotificationException(url, exMesg);
}
} catch (Exception e) {
String exMesg = "Refresh post to " + thisUrl + " for " + simpleName + " with id " + obj.getPk() + " threw an exception";
logger.error(exMesg, e);
throw new ClusterNotificationException(url, exMesg, e);
}
}
Aggregations