Example usage for org.springframework.mock.web MockHttpSession MockHttpSession

List of usage examples for org.springframework.mock.web MockHttpSession MockHttpSession

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpSession MockHttpSession.

Prototype

public MockHttpSession() 

Source Link

Document

Create a new MockHttpSession with a default MockServletContext .

Usage

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testVerifyUserPasswordNotSet() {
    User user = createUserWithoutPassword();
    String auth = user.getAuthorization(1);
    String view = controller.updatePasswordAndVerifyEmail(auth, user.getParam(), new MockHttpServletRequest(),
            map, new MockHttpSession());
    String expectedView = "register.setpassword";
    Assert.assertEquals(view, expectedView);
}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testVerifyUserPasswordNotSetWithDirectoryServerPullOn() {
    Configuration configuration = configurationService
            .locateConfigurationByName(Names.com_citrix_cpbm_portal_directory_service_enabled);
    configuration.setValue("true");
    configurationService.update(configuration);

    configuration = configurationService.locateConfigurationByName(Names.com_citrix_cpbm_directory_mode);
    configuration.setValue("pull");
    configurationService.update(configuration);

    User user = createUserWithoutPassword();
    String auth = user.getAuthorization(1);
    String view = controller.updatePasswordAndVerifyEmail(auth, user.getParam(), new MockHttpServletRequest(),
            map, new MockHttpSession());
    String expectedView = "redirect:/portal/verify_email";
    Assert.assertEquals(view, expectedView);
}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testVerifyUserEmailNotVerified() {
    User user = createUserWithoutEmailVerification();
    String auth = user.getAuthorization(1);
    String view = controller.updatePasswordAndVerifyEmail(auth, user.getParam(), new MockHttpServletRequest(),
            map, new MockHttpSession());
    String expectedView = "redirect:/portal/verify_email";
    Assert.assertEquals(view, expectedView);
}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testVerifyEnabledUser() {
    User user = createEmailVerifiedUser();
    String auth = user.getAuthorization(1);
    String view = controller.updatePasswordAndVerifyEmail(auth, user.getParam(), new MockHttpServletRequest(),
            map, new MockHttpSession());
    String expectedView = "redirect:/portal/login";
    Assert.assertEquals(view, expectedView);
}

From source file:fragment.web.BillingControllerTest.java

@Test
public void testShowHistory() {
    session = new MockHttpSession();
    Tenant tenant = createTestTenant(accountTypeDAO.getDefaultRegistrationAccountType());
    tenant.setState(com.vmops.model.Tenant.State.ACTIVE);
    tenant.setAccountType(accountTypeDAO.getDefaultRegistrationAccountType());
    User user = createTestUserInTenant(tenant);
    tenantService.setOwner(tenant, user);
    List<ProductBundle> bundles = productBundleService.listProductBundles(0, 0);
    ProductBundle nonVmBundle = null;//  w  w  w .j a v  a2s  . com
    for (ProductBundle bundle : bundles) {
        if (!bundle.getResourceType().getResourceTypeName().equals("VirtualMachine")) {
            nonVmBundle = bundle;
            break;
        }
    }
    tenant.getOwner().setEnabled(true);
    Subscription subscription = subscriptionService.createSubscription(tenant.getOwner(), nonVmBundle, null,
            null, false, false, null, new HashMap<String, String>());
    Assert.assertNotNull(subscription);
    request.setAttribute("isSurrogatedTenant", Boolean.TRUE);
    request.setAttribute("effectiveTenant", tenant);
    session.setAttribute("makepayment_status", "false");
    String view = controller.showHistory(tenant, tenant.getParam(), user.getParam(), "1", session, map,
            request);
    Assert.assertNotNull(view);
    Assert.assertTrue(map.containsAttribute("isPayAsYouGoChosen"));
    Assert.assertEquals(false, view.contentEquals("showUserProfile"));
    Assert.assertEquals(false, view.contentEquals("userHasCloudServiceAccount"));
    Assert.assertEquals(map.get("currentUser"), getRootUser());
    Assert.assertNotNull(map.get("billingActivities"));
    Assert.assertNotNull(map.get("users"));
    Assert.assertEquals(map.get("showUsers"), true);
    Assert.assertNotNull(map.get("tenant"));
    Assert.assertNotNull(map.get("statusMessage"));
    Assert.assertNull(map.get("makepayment_status"));

}

From source file:fragment.web.BillingControllerTest.java

@Test
public void testShowHistory1() {
    session = new MockHttpSession();

    Tenant tenant = createTestTenant(accountTypeDAO.getDefaultRegistrationAccountType());
    tenant.setState(com.vmops.model.Tenant.State.ACTIVE);
    tenant.setAccountType(accountTypeDAO.getDefaultRegistrationAccountType());
    User user = createTestUserInTenant(tenant);
    tenantService.setOwner(tenant, user);
    List<ProductBundle> bundles = productBundleService.listProductBundles(0, 0);
    ProductBundle nonVmBundle = null;/* ww  w  . j  a  v a2  s.  c om*/
    for (ProductBundle bundle : bundles) {
        if (!bundle.getResourceType().getResourceTypeName().equals("VirtualMachine")) {
            nonVmBundle = bundle;
            break;
        }
    }
    tenant.getOwner().setEnabled(true);
    Subscription subscription = subscriptionService.createSubscription(tenant.getOwner(), nonVmBundle, null,
            null, false, false, null, new HashMap<String, String>());
    Assert.assertNotNull(subscription);
    request.setAttribute("isSurrogatedTenant", Boolean.TRUE);
    request.setAttribute("effectiveTenant", tenant);
    session.setAttribute("makepayment_status", "true");
    String view = controller.showHistory(tenant, tenant.getParam(), user.getParam(), "1", session, map,
            request);
    Assert.assertNotNull(view);
    Assert.assertEquals(false, view.contentEquals("showUserProfile"));
    Assert.assertEquals(false, view.contentEquals("userHasCloudServiceAccount"));
    Assert.assertEquals(map.get("currentUser"), getRootUser());
    Assert.assertNotNull(map.get("billingActivities"));
    Assert.assertNotNull(map.get("users"));
    Assert.assertEquals(map.get("showUsers"), true);
    Assert.assertNotNull(map.get("tenant"));
    Assert.assertNotNull(map.get("statusMessage"));
    Assert.assertNull(map.get("makepayment_status"));

}

From source file:fragment.web.BillingControllerTest.java

@Test
public void testShowPaymentHistory() {
    session = new MockHttpSession();

    Tenant tenant = createTestTenant(accountTypeDAO.getDefaultRegistrationAccountType());
    tenant.setState(com.vmops.model.Tenant.State.ACTIVE);
    tenant.setAccountType(accountTypeDAO.getDefaultRegistrationAccountType());
    User user = createTestUserInTenant(tenant);
    tenantService.setOwner(tenant, user);
    List<ProductBundle> bundles = productBundleService.listProductBundles(0, 0);
    ProductBundle nonVmBundle = null;/*from  w  ww.jav a2s  .c o  m*/
    for (ProductBundle bundle : bundles) {
        if (!bundle.getResourceType().getResourceTypeName().equals("VirtualMachine")) {
            nonVmBundle = bundle;
            break;
        }
    }
    tenant.getOwner().setEnabled(true);
    Subscription subscription = subscriptionService.createSubscription(tenant.getOwner(), nonVmBundle, null,
            null, false, false, null, new HashMap<String, String>());
    Assert.assertNotNull(subscription);
    request.setAttribute("isSurrogatedTenant", Boolean.TRUE);
    request.setAttribute("effectiveTenant", tenant);
    session.setAttribute("makepayment_status", "true");
    String view = controller.showPaymentHistory(tenant, tenant.getParam(), "1", session, request, map);
    Assert.assertNotNull(view);

    Assert.assertNotNull(map.get("userHasCloudServiceAccount"));
    Assert.assertTrue(map.containsAttribute("isPayAsYouGoChosen"));
    Assert.assertNotNull(map.get("showUserProfile"));
    Assert.assertNotNull(map.get("errorMsg"));
    Assert.assertNotNull(map.get("tenant"));

    Assert.assertNotNull(map.get("errorMsg"));
    Assert.assertNotNull(map.get("salesLedgerRecords"));
    Assert.assertNotNull(map.get("enable_next"));
    Assert.assertNotNull(map.get("current_page"));

}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testEmailVerifiedEventForManualActivationAccountType() {
    // Sign up for manual activation account type
    MockHttpServletRequest mockRequest = getRequestTemplate(HttpMethod.GET, "/portal/register");
    UserRegistration registration = new UserRegistration();
    registration.setCountryList(countryService.getCountries(null, null, null, null, null, null, null));
    registration.setAcceptedTerms(true);
    List<AccountType> accountTypes = accountTypeDAO.getManualRegistrationAccountTypes();
    AccountType disposition = null;//from   ww w  .  j a v  a  2 s. c om
    for (AccountType accountType : accountTypes) {
        if (accountType.isManualActivation()) {
            disposition = accountType;
        }
    }
    BindingResult result = null;
    try {
        result = setupRegistration(disposition, registration);
    } catch (Exception e) {
        e.printStackTrace();
    }
    beforeRegisterCall(mockRequest, registration);
    String view = controller.register(registration, result, "abc", "abc", map, null, status, mockRequest);
    Assert.assertEquals("register.registration_success", view);
    Assert.assertTrue(status.isComplete());
    verifyRegistration(disposition, registration.getUser(), registration.getTenant());
    Assert.assertEquals(registration.getTenant().getObject(),
            ((com.citrix.cpbm.access.Tenant) map.get("tenant")).getObject());
    // account activation request event
    Assert.assertEquals(2, eventListener.getEvents().size());
    PortalEvent verifyEmailRequest = eventListener.getEvents().get(0);
    Assert.assertTrue(verifyEmailRequest.getPayload() instanceof VerifyEmailRequest);
    eventListener.clear();
    // verify email
    String auth = registration.getUser().getObject().getAuthorization(0);
    MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute("regAuth", auth);
    mockSession.setAttribute("regParam", registration.getUser().getObject().getParam());
    controller.verifyEmail(getRequestTemplate(HttpMethod.GET, "/verify_email"), map, mockSession);
    // Since tenant is not at activated, we will get only Welcome email
    Assert.assertEquals(1, eventListener.getEvents().size());
    PortalEvent event = eventListener.getEvents().get(0);
    Assert.assertTrue(event.getPayload() instanceof EmailVerified);
}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testWelcomeEmailEventForRetail() {
    // Sign up for manual activation account type
    MockHttpServletRequest mockRequest = getRequestTemplate(HttpMethod.GET, "/portal/register");
    UserRegistration registration = new UserRegistration();
    registration.setCountryList(countryService.getCountries(null, null, null, null, null, null, null));
    registration.setAcceptedTerms(true);
    AccountType disposition = accountTypeDAO.getDefaultSelfRegistrationAccountType();
    BindingResult result = null;/*  w w w. ja va  2  s.  co  m*/
    try {
        result = setupRegistration(disposition, registration);
    } catch (Exception e) {
        e.printStackTrace();
    }
    beforeRegisterCall(mockRequest, registration);
    controller.register(registration, result, "abc", "abc", map, null, status, mockRequest);
    // Tenant Activation Event
    // Assert.assertEquals(1, eventListener.getEvents().size());
    // PortalEvent tenantActivationEvent = eventListener.getEvents().get(0);
    // Assert.assertTrue(tenantActivationEvent.getPayload() instanceof TenantActivation);
    eventListener.clear();
    // verify email
    String auth = registration.getUser().getObject().getAuthorization(0);
    MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute("regAuth", auth);
    mockSession.setAttribute("regParam", registration.getUser().getObject().getParam());
    controller.verifyEmail(getRequestTemplate(HttpMethod.GET, "/verify_email"), map, mockSession);
    // Since tenant is at activated, we will get Email Verified event
    Assert.assertEquals(1, eventListener.getEvents().size());
}

From source file:fragment.web.RegistrationControllerTest.java

@Test
public void testWelcomeEmailAndActivationEmailEventsForRetail() {
    // Sign up for manual activation account type
    MockHttpServletRequest mockRequest = getRequestTemplate(HttpMethod.GET, "/portal/register");
    UserRegistration registration = new UserRegistration();
    registration.setCountryList(countryService.getCountries(null, null, null, null, null, null, null));
    registration.setAcceptedTerms(true);
    AccountType disposition = accountTypeDAO.getDefaultSelfRegistrationAccountType();
    BindingResult result = null;//from   w  w  w. j  a  va2s. c  om
    try {
        result = setupRegistration(disposition, registration);
    } catch (Exception e) {
        e.printStackTrace();
    }
    beforeRegisterCall(mockRequest, registration);
    controller.register(registration, result, "abc", "abc", map, null, status, mockRequest);
    // Tenant Activation Event
    // Assert.assertEquals(1, eventListener.getEvents().size());
    // PortalEvent tenantActivationEvent = eventListener.getEvents().get(0);
    // Assert.assertTrue(tenantActivationEvent.getPayload() instanceof TenantActivation);
    eventListener.clear();
    // verify email
    String auth = registration.getUser().getObject().getAuthorization(0);
    MockHttpSession mockSession = new MockHttpSession();
    mockSession.setAttribute("regAuth", auth);
    mockSession.setAttribute("regParam", registration.getUser().getObject().getParam());
    controller.verifyEmail(getRequestTemplate(HttpMethod.GET, "/verify_email"), map, mockSession);
    // Since tenant is at activated, we will get only Welcome email and ActivationEmail events
    Assert.assertEquals(1, eventListener.getEvents().size());
}