@Test
 public void testErrorChangeUserInfo() {
   final JSONObject jsonObject = new JSONObject();
   jsonObject.put("login", faker.name().firstName());
   jsonObject.put("password", faker.name().lastName());
   jsonObject.put("email", faker.internet().emailAddress());
   jsonObject.put("imgData", "");
   final Response json =
       target("user")
           .path("1")
           .request(MediaType.APPLICATION_JSON)
           .post(Entity.json(jsonObject.toString()));
   assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), json.getStatus());
 }
예제 #2
0
  public static TestPerson randomPerson() {
    Random random = new Random();

    TestPerson randomPerson = new TestPerson();

    PropertyMap pm = randomPerson.getPropertyMap();

    Name fakeName = faker.name();

    pm.put("firstName", fakeName.firstName());
    pm.put("lastName", fakeName.lastName());
    pm.put("email", faker.internet().emailAddress());

    if (random.nextBoolean()) {
      Business bInfo = faker.business();
      pm.put("creditCard.Type", bInfo.creditCardType());
      pm.put("creditCard.Number", bInfo.creditCardNumber());
      pm.put("creditCard.Expiry", bInfo.creditCardExpiry());
    }

    return randomPerson;
  }
  @Override
  protected Application configure() {
    faker = new Faker();

    final Configuration configuration;
    try {
      configuration = new Configuration(CONFIG);
    } catch (IOException | NumberFormatException e) {
      System.out.println("Properties error:");
      System.out.println(e.getMessage());
      System.exit(1);
      return null;
    }

    final AccountServiceImpl accountService;
    try {
      accountService =
          new AccountServiceImpl(
              configuration.getDbName(),
              configuration.getDbHost(),
              configuration.getDbPort(),
              configuration.getDbUsername(),
              configuration.getDbPassword());
    } catch (SQLException | IOException e) {
      e.printStackTrace();
      System.exit(1);
      return null;
    }

    final ResourceConfig config = new ResourceConfig(Session.class, Users.class);
    config.register(new AccountServiceAbstractBinder(accountService));
    final HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    final HttpSession httpSession = mock(HttpSession.class);
    final String sessionId = faker.lorem().fixedString(15);
    Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession);
    Mockito.when(httpSession.getId()).thenReturn(sessionId);

    config.register(new ServletAbstractBinder(httpServletRequest));
    return config;
  }