コード例 #1
0
  @Test
  public void testLoginToSaasWhenNullAccountReference() throws Exception {
    Credentials testSaasUsernameAndPassword =
        Commons.createDtoFromJson(TEST_CREDENTIALS_JSON, Credentials.class);

    doReturn(new DtoServerImpls.TokenImpl().withValue(TEST_ACCESS_TOKEN))
        .when(mockFacade)
        .loginToCodenvySaaS(testSaasUsernameAndPassword);
    doReturn(null).when(mockFacade).getAccountWhereUserIsOwner(null, TEST_ACCESS_TOKEN);

    Response response = service.loginToCodenvySaaS(testSaasUsernameAndPassword);
    assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
  }
コード例 #2
0
  @Test
  public void testLoginToSaas() throws Exception {
    Credentials testSaasUsernameAndPassword =
        Commons.createDtoFromJson(TEST_CREDENTIALS_JSON, Credentials.class);

    doReturn(new DtoServerImpls.TokenImpl().withValue(TEST_ACCESS_TOKEN))
        .when(mockFacade)
        .loginToCodenvySaaS(testSaasUsernameAndPassword);
    doReturn(
            new org.eclipse.che.api.account.server.dto.DtoServerImpls.AccountReferenceImpl()
                .withId(TEST_ACCOUNT_ID)
                .withName(TEST_ACCOUNT_NAME))
        .when(mockFacade)
        .getAccountWhereUserIsOwner(null, TEST_ACCESS_TOKEN);

    Response result = service.loginToCodenvySaaS(testSaasUsernameAndPassword);
    assertEquals(result.getStatus(), Response.Status.OK.getStatusCode());

    assertNotNull(service.saasUserCredentials);

    SaasUserCredentials testSaasSaasUserCredentials = service.saasUserCredentials;
    assertEquals(testSaasSaasUserCredentials.getAccountId(), TEST_ACCOUNT_ID);
    assertEquals(testSaasSaasUserCredentials.getToken(), TEST_ACCESS_TOKEN);
  }
コード例 #3
0
  @Test
  public void testGetSubscription() throws Exception {
    SaasUserCredentials testUserCredentials =
        new SaasUserCredentials(TEST_ACCOUNT_ID, TEST_ACCESS_TOKEN);

    SimpleDateFormat subscriptionDateFormat =
        new SimpleDateFormat(SaasAccountServiceProxy.SUBSCRIPTION_DATE_FORMAT);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    String startDate = subscriptionDateFormat.format(cal.getTime());
    cal.add(Calendar.DATE, 2);
    String endDate = subscriptionDateFormat.format(cal.getTime());

    String testSubscriptionDescriptorJson =
        "{\n"
            + "  \"description\": \"On-Prem Commercial 25 Users\",\n"
            + "  \"startDate\" : \""
            + startDate
            + "\",\n"
            + "  \"endDate\" : \""
            + endDate
            + "\",\n"
            + "  \"links\": [\n"
            + "    {\n"
            + "      \"href\": \"https://codenvy-stg"
            + ".com/api/account/subscriptions/subscriptionoxmrh93dw3ceuegk\",\n"
            + "      \"rel\": \"get subscription by id\",\n"
            + "      \"produces\": \"application/json\",\n"
            + "      \"parameters\": [],\n"
            + "      \"method\": \"GET\"\n"
            + "    }\n"
            + "  ],\n"
            + "  \"properties\": {\n"
            + "    \"Users\": \"25\",\n"
            + "    \"Package\": \"Commercial\"\n"
            + "  },\n"
            + "  \"id\": \"subscriptionoxmrh93dw3ceuegk\",\n"
            + "  \"state\": \"ACTIVE\"\n"
            + "}";
    SubscriptionDescriptor descriptor =
        DtoFactory.getInstance()
            .createDtoFromJson(testSubscriptionDescriptorJson, SubscriptionDescriptor.class);
    doReturn(descriptor)
        .when(mockFacade)
        .getSaasSubscription(SaasAccountServiceProxy.ON_PREMISES, testUserCredentials);

    service.saasUserCredentials = testUserCredentials;

    Response result = service.getOnPremisesSaasSubscription();
    assertEquals(result.getStatus(), Response.Status.OK.getStatusCode());
    SubscriptionDescriptor subscription =
        Commons.createDtoFromJson((String) result.getEntity(), SubscriptionDescriptor.class);
    assertEquals(subscription.getDescription(), "On-Prem Commercial 25 Users");
    assertEquals(subscription.getStartDate(), startDate);
    assertEquals(subscription.getEndDate(), endDate);
    assertTrue(subscription.getLinks().isEmpty());
    assertEquals(subscription.getId(), "subscriptionoxmrh93dw3ceuegk");
    assertEquals(subscription.getState().name(), "ACTIVE");
    assertEquals(subscription.getProperties().get("Users"), "25");
    assertEquals(subscription.getProperties().get("Package"), "Commercial");

    doThrow(new HttpException(500, "error"))
        .when(mockFacade)
        .getSaasSubscription(SaasAccountServiceProxy.ON_PREMISES, testUserCredentials);
    result = service.getOnPremisesSaasSubscription();
    assertErrorResponse(result);
  }