Search in sources :

Example 1 with MockHttpRequestExecuter

use of com.openmeap.util.MockHttpRequestExecuter 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));
}
Also used : ClusterNode(com.openmeap.model.dto.ClusterNode) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ModelManager(com.openmeap.model.ModelManager) MockHttpRequestExecuter(com.openmeap.util.MockHttpRequestExecuter) NonStrictExpectations(mockit.NonStrictExpectations) Application(com.openmeap.model.dto.Application) ModelEntityModifyEvent(com.openmeap.model.event.ModelEntityModifyEvent) Test(org.junit.Test)

Aggregations

ModelManager (com.openmeap.model.ModelManager)1 Application (com.openmeap.model.dto.Application)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 ModelEntityModifyEvent (com.openmeap.model.event.ModelEntityModifyEvent)1 MockHttpRequestExecuter (com.openmeap.util.MockHttpRequestExecuter)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Test (org.junit.Test)1