Search in sources :

Example 1 with AddModifyApplicationVersionBacking

use of com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking 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);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) HashMap(java.util.HashMap) ProcessingEvent(com.openmeap.event.ProcessingEvent) ModelManager(com.openmeap.model.ModelManager) AddModifyApplicationVersionBacking(com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking) Application(com.openmeap.model.dto.Application)

Example 2 with AddModifyApplicationVersionBacking

use of com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking in project OpenMEAP by OpenMEAP.

the class AddModifyApplicationVersionsBackingTest method testFormPost.

@Test
public void testFormPost() {
    ApplicationVersion version = null;
    Map<Object, Object> vars = null;
    Map<Object, Object> parms = null;
    // //////////
    // Verify that we can create a new ApplicationVersion
    vars = new HashMap<Object, Object>();
    parms = new HashMap<Object, Object>();
    parms.put(FormConstants.PROCESS_TARGET, new String[] { ProcessingTargets.ADDMODIFY_APPVER });
    parms.put(FormConstants.APP_ID, new String[] { "1" });
    parms.put("versionId", new String[] { "" });
    parms.put("identifier", new String[] { "ApplicationVersion.identifier.1" });
    parms.put("url", new String[] { "ANewDownloadUrl" });
    parms.put("hashType", new String[] { "MD5" });
    parms.put("hash", new String[] { "ANewHashValue" });
    parms.put("notes", new String[] { "These are them application version notes" });
    parms.put("deviceTypes", new String[] { "1", "2" });
    parms.put("bytesLength", new String[] { "13456342" });
    parms.put("bytesLengthUncompressed", new String[] { "13456342" });
    AddModifyApplicationVersionBacking amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(modelManager);
    Collection<ProcessingEvent> events = amab.process(null, vars, parms);
    Assert.assertTrue(events.size() == 4 && ProcessingUtils.containsTarget(events, ProcessingTargets.MESSAGES));
    Assert.assertTrue(vars.get("hashTypes") != null);
    Assert.assertTrue(vars.get(FormConstants.PROCESS_TARGET) != null && ((String) vars.get(FormConstants.PROCESS_TARGET)).compareTo(ProcessingTargets.ADDMODIFY_APPVER) == 0);
    Assert.assertTrue(vars.get("version") != null);
    version = ((ApplicationVersion) vars.get("version"));
    Assert.assertTrue(version.getIdentifier().compareTo("ApplicationVersion.identifier.1") == 0);
    Assert.assertTrue(version.getArchive() != null);
    // ///////////
    // Verify that we can change pretty much everything
    Long ourVersionId = ((ApplicationVersion) vars.get("version")).getId();
    parms.put("versionId", new String[] { ourVersionId.toString() });
    parms.put("identifier", new String[] { "ApplicationVersion.new_version.identifier" });
    parms.put("url", new String[] { "AnotherNewDownloadUrl" });
    parms.put("hashType", new String[] { "SHA1" });
    parms.put("hash", new String[] { "AnotherNewHashValue" });
    parms.put("notes", new String[] { "New notes" });
    parms.put("deviceTypes", new String[] { "1" });
    parms.put("bytesLength", new String[] { "10000" });
    parms.put("bytesLengthUncompressed", new String[] { "10000" });
    amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(modelManager);
    events = amab.process(null, vars, parms);
    version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, ourVersionId);
    Assert.assertTrue(version.getIdentifier().compareTo("ApplicationVersion.new_version.identifier") == 0);
    Assert.assertTrue(version.getArchive().getUrl().compareTo("AnotherNewDownloadUrl") == 0);
    Assert.assertTrue(version.getArchive().getHashAlgorithm().compareTo("SHA1") == 0);
    Assert.assertTrue(version.getArchive().getHash().compareTo("AnotherNewHashValue") == 0);
    Assert.assertTrue(version.getNotes().compareTo("New notes") == 0);
    Assert.assertTrue(version.getArchive().getBytesLength() == 10000);
    Assert.assertTrue(version.getArchive().getBytesLengthUncompressed() == 10000);
    // ///////////
    // Verify that we cannot change an inactive version
    ourVersionId = ((ApplicationVersion) vars.get("version")).getId();
    ((ApplicationVersion) vars.get("version")).setActiveFlag(false);
    parms.put("versionId", new String[] { ourVersionId.toString() });
    parms.put("identifier", new String[] { "ApplicationVersion.new_version_2.identifier" });
    parms.put("url", new String[] { "AnotherNewDownloadUrl2" });
    parms.put("hashType", new String[] { "MD5" });
    parms.put("hash", new String[] { "AnotherNewHashValue2" });
    parms.put("notes", new String[] { "New notes2" });
    parms.put("deviceTypes", new String[] { "12" });
    parms.put("bytesLength", new String[] { "100002" });
    parms.put("bytesLengthUncompressed", new String[] { "100002" });
    amab = new AddModifyApplicationVersionBacking();
    amab.setModelManager(modelManager);
    events = amab.process(null, vars, parms);
    version = modelManager.getModelService().findByPrimaryKey(ApplicationVersion.class, ourVersionId);
    Assert.assertTrue(version.getIdentifier().compareTo("ApplicationVersion.new_version.identifier") == 0);
    Assert.assertTrue(version.getArchive().getUrl().compareTo("AnotherNewDownloadUrl") == 0);
    Assert.assertTrue(version.getArchive().getHashAlgorithm().compareTo("SHA1") == 0);
    Assert.assertTrue(version.getArchive().getHash().compareTo("AnotherNewHashValue") == 0);
    Assert.assertTrue(version.getNotes().compareTo("New notes") == 0);
    Assert.assertTrue(version.getArchive().getBytesLength() == 10000);
    Assert.assertTrue(version.getArchive().getBytesLengthUncompressed() == 10000);
}
Also used : ApplicationVersion(com.openmeap.model.dto.ApplicationVersion) ProcessingEvent(com.openmeap.event.ProcessingEvent) AddModifyApplicationVersionBacking(com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking)

Aggregations

AddModifyApplicationVersionBacking (com.openmeap.admin.web.backing.AddModifyApplicationVersionBacking)2 ProcessingEvent (com.openmeap.event.ProcessingEvent)2 ApplicationVersion (com.openmeap.model.dto.ApplicationVersion)2 ModelManager (com.openmeap.model.ModelManager)1 Application (com.openmeap.model.dto.Application)1 HashMap (java.util.HashMap)1