use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AdminTest method testDeleteApplication.
public void testDeleteApplication() throws Exception {
ModelManager modelManager = helper.getModelManager();
Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
HttpResponse response = helper.postAddModifyApp_delete(dbApp);
modelManager.getModelService().clearPersistenceContext();
dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(dbApp == null);
Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_01_HASH));
Assert.assertTrue(!_isVersionArchiveInAdminLocation(VERSION_02_HASH));
Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_01_HASH));
Assert.assertTrue(!_isVersionArchiveInDeployedLocation(VERSION_02_HASH));
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class AdminTest method testModifyApplication.
public void testModifyApplication() throws Exception {
Application dbApp = modelManager.getModelService().findApplicationByName(APP_NAME);
Assert.assertTrue(dbApp != null);
// make some changes
String newDesc = "Creating a new description";
Integer newLen = 2;
dbApp.setDescription(newDesc);
dbApp.setDeploymentHistoryLength(newLen);
Utils.consumeInputStream(helper.postAddModifyApp(dbApp).getResponseBody());
// validate changes
modelManager.refresh(dbApp, null);
Assert.assertTrue(dbApp.getDescription().equals(newDesc));
Assert.assertTrue(dbApp.getDeploymentHistoryLength().equals(newLen));
// TODO: validate changes are reflected by services-web, from the refresh hit
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServiceImpl method connectionOpen.
public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
String reqAppArchHashVal = StringUtils.trimToNull(request.getApplication().getHashValue());
String reqAppVerId = StringUtils.trimToNull(request.getApplication().getVersionId());
String reqAppName = StringUtils.trimToNull(request.getApplication().getName());
ConnectionOpenResponse response = new ConnectionOpenResponse();
GlobalSettings settings = modelManager.getGlobalSettings();
if (StringUtils.isBlank(settings.getExternalServiceUrlPrefix()) && logger.isWarnEnabled()) {
logger.warn("The external service url prefix configured in the admin interface is blank. " + "This will probably cause issues downloading application archives.");
}
Application application = getApplication(reqAppName, reqAppVerId);
// Generate a new auth token for the device to present to the proxy
String authToken;
try {
authToken = AuthTokenProvider.newAuthToken(application.getProxyAuthSalt());
} catch (DigestException e) {
throw new GenericRuntimeException(e);
}
response.setAuthToken(authToken);
// If there is a deployment,
// and the version of that deployment differs in hash value or identifier
// then return an update in the response
Deployment lastDeployment = modelManager.getModelService().getLastDeployment(application);
Boolean reqAppVerDiffers = lastDeployment != null && !lastDeployment.getVersionIdentifier().equals(reqAppVerId);
Boolean reqAppArchHashValDiffers = lastDeployment != null && reqAppArchHashVal != null && !lastDeployment.getApplicationArchive().getHash().equals(reqAppArchHashVal);
// the app hash value is different than reported
if (reqAppVerDiffers || reqAppArchHashValDiffers) {
// TODO: I'm not happy with the discrepancies between the model and schema
// ...besides, this update header should be encapsulated somewhere else
ApplicationArchive currentVersionArchive = lastDeployment.getApplicationArchive();
UpdateHeader uh = new UpdateHeader();
uh.setVersionIdentifier(lastDeployment.getVersionIdentifier());
uh.setInstallNeeds(Long.valueOf(currentVersionArchive.getBytesLength() + currentVersionArchive.getBytesLengthUncompressed()));
uh.setStorageNeeds(Long.valueOf(currentVersionArchive.getBytesLengthUncompressed()));
uh.setType(UpdateType.fromValue(lastDeployment.getType().toString()));
uh.setUpdateUrl(currentVersionArchive.getDownloadUrl(settings));
uh.setHash(new Hash());
uh.getHash().setAlgorithm(HashAlgorithm.fromValue(currentVersionArchive.getHashAlgorithm()));
uh.getHash().setValue(currentVersionArchive.getHash());
response.setUpdate(uh);
}
return response;
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ModelServiceImplTest method testSaveOrUpdate.
public void testSaveOrUpdate() {
/////////////////
// Verify that we can create and save an applicaiton
// and that the application returned has the pk assigned by the db/orm
Application app = new Application();
app.setName("This is a unique app name, or my name ain't Jon.");
try {
app = modelService.begin().saveOrUpdate(app);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
Assert.assertTrue(app.getId() != null);
ApplicationVersion appVer = new ApplicationVersion();
appVer.setApplication(app);
appVer.setIdentifier("smacky id");
try {
appVer = modelService.begin().saveOrUpdate(appVer);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
Assert.assertTrue(appVer.getId() != null);
/////////////////
// Verify that we can modify an application
app = modelService.findByPrimaryKey(Application.class, 1L);
String origName = app.getName();
app.setName("picard");
try {
app = modelService.begin().saveOrUpdate(app);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
app = modelService.findByPrimaryKey(Application.class, 1L);
Assert.assertTrue(app.getName() != null && app.getName().compareTo("picard") == 0);
Assert.assertTrue(app.getId() != null);
// put the app back the way we found it
app.setName(origName);
try {
app = modelService.begin().saveOrUpdate(app);
modelService.commit();
} catch (Exception e) {
modelService.rollback();
throw new RuntimeException(e);
}
}
use of com.openmeap.model.dto.Application in project OpenMEAP by OpenMEAP.
the class ModelServiceRefreshNotifierTest method testHandlePostSaveOrUpdate.
@Test
public void testHandlePostSaveOrUpdate() throws Exception {
try {
new NonStrictExpectations() {
{
}
};
} catch (Exception e) {
}
;
MockHttpRequestExecuter.setResponseCode(200);
MockHttpRequestExecuter.setResponseText("");
MockHttpRequestExecuter httpExecuter = new MockHttpRequestExecuter();
final ModelManager modelManager = new MockModelManager();
final GlobalSettings globalSettings = new GlobalSettings();
globalSettings.setServiceManagementAuthSalt(UUID.randomUUID().toString());
ClusterNode clusterNode = new ClusterNode();
clusterNode.setServiceWebUrlPrefix("http://www.openmeap.com/openmeap-services-web");
globalSettings.addClusterNode(clusterNode);
new NonStrictExpectations(globalSettings, modelManager) {
{
modelManager.getGlobalSettings();
result = globalSettings;
}
};
Application app = new Application();
app.setName("Happy Name");
app.setId(1L);
ModelServiceRefreshNotifier notifier = new ModelServiceRefreshNotifier();
notifier.setModelManager(modelManager);
notifier.setHttpRequestExecuter(httpExecuter);
notifier.notify(new ModelEntityModifyEvent(app), null);
String lastPostUrl = MockHttpRequestExecuter.getLastPostUrl();
Map<String, Object> lastPostData = MockHttpRequestExecuter.getLastPostData();
String uri = lastPostUrl;
String type = (String) lastPostData.get("type");
String auth = (String) lastPostData.get("auth");
String id = (String) lastPostData.get("id").toString();
Assert.assertTrue(uri.equals("http://www.openmeap.com/openmeap-services-web/service-management/"));
Assert.assertTrue(id.equals("1"));
Assert.assertTrue(type.equals("Application"));
Assert.assertTrue(AuthTokenProvider.validateAuthToken(globalSettings.getServiceManagementAuthSalt(), auth));
}
Aggregations