Пример #1
0
 @Test
 public void shutdownServerDoesNotRespond() {
   getDefaultServer().shutdown();
   Assertions.assertThat(getLastMessage()).isNull();
   sendMessage(new CorfuMsg(CorfuMsgType.PING));
   Assertions.assertThat(getLastMessage()).isNull();
 }
Пример #2
0
  @Test
  public void deleteLogsByVersion() {
    KieSession kieSession = createKSession(HELLO_WORLD_PROCESS);
    startProcess(kieSession, HELLO_WORLD_PROCESS_ID, 7);
    disposeRuntimeManager();
    kieSession = createKSession(HELLO_WORLD_PROCESS2);
    startProcess(kieSession, HELLO_WORLD_PROCESS2_ID, 2);

    // Delete all logs of version 1.1
    ProcessInstanceLogDeleteBuilder deleteBuilder =
        auditService.processInstanceLogDelete().processVersion("1.0");
    int deleteResult = deleteBuilder.build().execute();
    Assertions.assertThat(deleteResult).isEqualTo(7);

    // Make sure that the 1.1 version logs are gone
    List<ProcessInstanceLog> resultList =
        auditService.processInstanceLogQuery().processVersion("1.0").build().getResultList();
    Assertions.assertThat(resultList).hasSize(0);

    // Now check that 1.0 version logs are present
    resultList =
        auditService.processInstanceLogQuery().processVersion("1.1").build().getResultList();
    Assertions.assertThat(resultList).hasSize(2);
    Assertions.assertThat(resultList).extracting("processVersion").containsExactly("1.1", "1.1");
  }
Пример #3
0
  @Test
  public void testCrud() throws Exception {
    Long id = dao.addUser(user);
    assertThat(id).isEqualTo(1l);

    User u;
    u = dao.getUserById(1l);
    assertThat(u.getFullName()).isEqualTo("test deneme");

    dao.updateAvatar(1l, "test deneme");

    u = dao.getUserByEmail("*****@*****.**");
    assertThat(u.getFullName()).isEqualTo("test deneme");
    assertThat(u.getAvatarUrl()).isEqualTo("test deneme");

    u.setBio("test bio");
    dao.updateUser(u);

    u = dao.getUserById(1l);
    assertThat(u.getBio()).isEqualTo("test bio");

    assertThat(dao.userExists(1l));
    assertThat(dao.userExistsByEmail("*****@*****.**"));

    dao.banUser(1l);
    u = dao.getUserById(1l);
    assertThat(u.getIsBanned());
  }
Пример #4
0
  @Test
  public void testFollow() throws Exception {
    User u = mapper.readValue(fixture("fixtures/user.json"), User.class);

    Long id = dao.addUser(u);
    assertThat(id).isEqualTo(1l);

    id = dao.addUser(u);
    assertThat(id).isEqualTo(2l);

    assertThat(!dao.follows(1l, 2l));

    assertThat(dao.getFollowers(1l).size()).isEqualTo(0);
    assertThat(dao.getFollowing(1l).size()).isEqualTo(0);

    dao.followUser(1l, 2l);

    assertThat(dao.follows(1l, 2l));

    assertThat(dao.getFollowing(1l).size()).isEqualTo(1);
    assertThat(dao.getFollowers(2l).size()).isEqualTo(1);

    assertThat(dao.getFollowing(1l).get(0).getId()).isEqualTo(2l);
    assertThat(dao.getFollowers(2l).get(0).getId()).isEqualTo(1l);

    dao.unfollowUser(1l, 2l);

    assertThat(!dao.follows(1l, 2l));

    assertThat(dao.getFollowers(1l).size()).isEqualTo(0);
    assertThat(dao.getFollowing(1l).size()).isEqualTo(0);
  }
  /** This method tests the {@code isOfType} assertion method. */
  @Test
  @NeedReload
  public void test_is_of_type() {
    Changes changes = new Changes(source).setStartPointNow();
    update("update test set var14 = 1 where var1 = 1");
    update(
        "insert into test(var1, var2, var11, var10, var9, var3, var12, var8) values(5, true, FILE_READ('classpath:h2-logo-2.png'), '2014-05-24 09:46:30', '2014-05-24', 3, 'test', '09:46:30')");
    changes.setEndPointNow();
    Table table = new Table(source, "test");
    Table table2 = new Table(source, "test2");

    ChangeColumnAssert changeColumnAssert1 = assertThat(changes).change().column("var2");
    ChangeColumnAssert changeColumnAssertReturn1 =
        changeColumnAssert1.isOfType(ValueType.BOOLEAN, true);
    Assertions.assertThat(changeColumnAssert1).isSameAs(changeColumnAssertReturn1);
    ChangeColumnAssert changeColumnAssert2 = assertThat(changes).change(1).column("var2");
    ChangeColumnAssert changeColumnAssertReturn2 =
        changeColumnAssert2.isOfType(ValueType.BOOLEAN, false);
    Assertions.assertThat(changeColumnAssert2).isSameAs(changeColumnAssertReturn2);
    TableColumnAssert tableColumnAssert1 = assertThat(table).column("var2");
    TableColumnAssert tableColumnAssertReturn1 =
        tableColumnAssert1.isOfType(ValueType.BOOLEAN, false);
    Assertions.assertThat(tableColumnAssert1).isSameAs(tableColumnAssertReturn1);
    TableColumnAssert tableColumnAssert2 = assertThat(table2).column("var2");
    TableColumnAssert tableColumnAssertReturn2 =
        tableColumnAssert2.isOfType(ValueType.BOOLEAN, true);
    Assertions.assertThat(tableColumnAssert2).isSameAs(tableColumnAssertReturn2);
  }
Пример #6
0
  @Test
  @BZ("1188702")
  public void testDeleteLogsByDate() {
    kieSession = createKSession(HUMAN_TASK);

    processInstanceList = startProcess(kieSession, HUMAN_TASK_ID, 4);

    TaskService taskService = getRuntimeEngine().getTaskService();

    // Delete the last two task logs
    for (int i = processInstanceList.size() - 1; i > 0; i--) {
      List<Long> taskIdList =
          taskService.getTasksByProcessInstanceId(processInstanceList.get(i).getId());
      Assertions.assertThat(taskIdList).hasSize(1);

      Task task = taskService.getTaskById(taskIdList.get(0));
      Assertions.assertThat(task).isNotNull();

      int resultCount =
          taskAuditService
              .auditTaskDelete()
              .date(task.getTaskData().getCreatedOn())
              .build()
              .execute();
      Assertions.assertThat(resultCount).isEqualTo(1);
    }
  }
Пример #7
0
  @Test
  public void should_expose_isDownloaded() {
    org.assertj.core.api.Assertions.assertThat(ITEM.isDownloaded()).isTrue();

    ITEM.setFileName(null);
    org.assertj.core.api.Assertions.assertThat(ITEM.isDownloaded()).isFalse();
  }
  @Test
  @SuppressWarnings("squid:S2925")
  public void testThatMappingFromTemplateIsApplied() throws Exception {
    registry.counter(name("test", "cache-evictions")).inc();
    reportAndRefresh();

    // somehow the cluster state is not immediately updated... need to check
    Thread.sleep(200);
    ClusterStateResponse clusterStateResponse =
        client()
            .admin()
            .cluster()
            .prepareState()
            .setRoutingTable(false)
            .setLocal(false)
            .setNodes(true)
            .setIndices(indexWithDate)
            .execute()
            .actionGet();

    org.assertj.core.api.Assertions.assertThat(
            clusterStateResponse.getState().getMetaData().getIndices().containsKey(indexWithDate))
        .isTrue();
    IndexMetaData indexMetaData =
        clusterStateResponse.getState().getMetaData().getIndices().get(indexWithDate);
    org.assertj.core.api.Assertions.assertThat(indexMetaData.getMappings().containsKey("counter"))
        .isTrue();
    Map<String, Object> properties =
        getAsMap(indexMetaData.mapping("counter").sourceAsMap(), "properties");
    Map<String, Object> mapping = getAsMap(properties, "name");
    org.assertj.core.api.Assertions.assertThat(mapping).containsKey("index");
    org.assertj.core.api.Assertions.assertThat(mapping.get("index").toString())
        .isEqualTo("not_analyzed");
  }
Пример #9
0
  @Test
  public void issue_33() {
    String json =
        "{ \"store\": {\n"
            + "    \"book\": [ \n"
            + "      { \"category\": \"reference\",\n"
            + "        \"author\": {\n"
            + "          \"name\": \"Author Name\",\n"
            + "          \"age\": 36\n"
            + "        },\n"
            + "        \"title\": \"Sayings of the Century\",\n"
            + "        \"price\": 8.95\n"
            + "      },\n"
            + "      { \"category\": \"fiction\",\n"
            + "        \"author\": \"Evelyn Waugh\",\n"
            + "        \"title\": \"Sword of Honour\",\n"
            + "        \"price\": 12.99,\n"
            + "        \"isbn\": \"0-553-21311-3\"\n"
            + "      }\n"
            + "    ],\n"
            + "    \"bicycle\": {\n"
            + "      \"color\": \"red\",\n"
            + "      \"price\": 19.95\n"
            + "    }\n"
            + "  }\n"
            + "}";

    List<Map<String, Object>> result = read(json, "$.store.book[?(@.author.age == 36)]");

    Assertions.assertThat(result).hasSize(1);
    Assertions.assertThat(result.get(0)).containsEntry("title", "Sayings of the Century");
  }
Пример #10
0
  @Test
  public void issue_43() {

    String json = "{\"test\":null}";

    Assertions.assertThat(read(json, "test")).isNull();

    Assertions.assertThat(
            JsonPath.using(
                    Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS))
                .parse(json)
                .read("nonExistingProperty"))
        .isNull();

    try {
      read(json, "nonExistingProperty");

      failBecauseExceptionWasNotThrown(PathNotFoundException.class);
    } catch (PathNotFoundException e) {

    }

    try {
      read(json, "nonExisting.property");

      failBecauseExceptionWasNotThrown(PathNotFoundException.class);
    } catch (PathNotFoundException e) {
    }
  }
  /** This method should fail because the value is not null. */
  @Test
  @NeedReload
  public void should_fail_because_value_is_not_null() {
    Table table = new Table(source, "test");
    Changes changes = new Changes(table).setStartPointNow();
    update("update test set var14 = 1 where var1 = 1");
    changes.setEndPointNow();

    try {
      assertThat(changes).change().column("var3").valueAtEndPoint().isNull();
      fail("An exception must be raised");
    } catch (AssertionError e) {
      Assertions.assertThat(e.getMessage())
          .isEqualTo(
              String.format(
                  "[Value at end point of Column at index 2 (column name : VAR3) of Change at index 0 (with primary key : [1]) of Changes on TEST table of 'sa/jdbc:h2:mem:test' source] expected:<null> but was:<2>"));
    }
    try {
      assertThat(table).column("var3").value().isNull();
      fail("An exception must be raised");
    } catch (AssertionError e) {
      Assertions.assertThat(e.getMessage())
          .isEqualTo(
              String.format(
                  "[Value at index 0 of Column at index 2 (column name : VAR3) of TEST table] expected:<null> but was:<2>"));
    }
  }
Пример #12
0
  @Test
  public void deleteLogsByProcessName() {
    KieSession kieSession = createKSession(HELLO_WORLD_PROCESS);

    startProcess(kieSession, HELLO_WORLD_PROCESS_ID, 2);

    // Check that all records are created.
    List<ProcessInstanceLog> resultList =
        auditService
            .processInstanceLogQuery()
            .processId(HELLO_WORLD_PROCESS_ID)
            .processVersion("1.0")
            .build()
            .getResultList();
    Assertions.assertThat(resultList).hasSize(2);
    Assertions.assertThat(resultList)
        .extracting("processName")
        .containsExactly(HELLO_WORLD_P1NAME, HELLO_WORLD_P1NAME);

    // Perform delete
    int resultCount =
        auditService.processInstanceLogDelete().processName(HELLO_WORLD_P1NAME).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(2);

    // Check that all records are gone
    resultList =
        auditService
            .processInstanceLogQuery()
            .processId(HELLO_WORLD_PROCESS_ID)
            .processVersion("1.0")
            .build()
            .getResultList();
    Assertions.assertThat(resultList).hasSize(0);
  }
Пример #13
0
  @Test
  public void should_expose_the_API_url() {
    org.assertj.core.api.Assertions.assertThat(ITEM.getProxyURLWithoutExtention())
        .isEqualTo("/api/podcast/1/items/1/download");

    org.assertj.core.api.Assertions.assertThat(ITEM.getProxyURL())
        .isEqualTo("/api/podcast/1/items/1/download.mp4");
  }
Пример #14
0
  @Test
  public void should_report_parent_podcast_cover() {
    org.assertj.core.api.Assertions.assertThat(ITEM.getCoverOfItemOrPodcast()).isSameAs(COVER);

    ITEM.setCover(null);
    org.assertj.core.api.Assertions.assertThat(ITEM.getCoverOfItemOrPodcast())
        .isSameAs(PODCAST_COVER);
  }
  @Test
  public void testGroupExistsSystemProperties() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();

    boolean groupExists = ldapUserGroupCallback.existsGroup("manager");
    Assertions.assertThat(groupExists).isTrue();
  }
  @Test
  public void testGroupsForUserSystemProperties() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();

    List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john", null, null);
    Assertions.assertThat(userGroups).hasSize(1);
  }
  @Test
  public void testUserExistsSystemProperties() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();

    boolean userExists = ldapUserGroupCallback.existsUser("john");
    Assertions.assertThat(userExists).isTrue();
  }
Пример #18
0
  @Test
  public void should_get_the_local_path() {
    /* When */ Path localPath = ITEM.getLocalPath();
    /* Then */ org.assertj.core.api.Assertions.assertThat(localPath).hasFileName("fakeItem.mp4");

    /* When */ String localStringPath = ITEM.getLocalUri();
    /* Then */ org.assertj.core.api.Assertions.assertThat(localStringPath)
        .isEqualTo("/tmp/Fake Podcast/fakeItem.mp4");
  }
Пример #19
0
  @Test
  public void should_report_parent_podcast_id() {
    org.assertj.core.api.Assertions.assertThat(ITEM.getPodcastId()).isEqualTo(PODCAST.getId());

    ITEM.setPodcast(null);
    org.assertj.core.api.Assertions.assertThat(ITEM.getPodcastId())
        .isNotEqualTo(PODCAST.getId())
        .isNull();
  }
 @Test
 public void gettersReturnCorrectData() {
   UsernamePasswordAuthenticationToken token =
       new UsernamePasswordAuthenticationToken(
           "Test", "Password", AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
   assertThat(token.getPrincipal()).isEqualTo("Test");
   assertThat(token.getCredentials()).isEqualTo("Password");
   assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains("ROLE_ONE"));
   assertThat(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains("ROLE_TWO"));
 }
Пример #21
0
  @Test
  public void testDeleteLogsByProcessId() {
    kieSession = createKSession(HUMAN_TASK);

    processInstanceList = startProcess(kieSession, HUMAN_TASK_ID, 2);

    int deletedLogs = taskAuditService.auditTaskDelete().processId(HUMAN_TASK_ID).build().execute();
    Assertions.assertThat(deletedLogs).isEqualTo(2);
    Assertions.assertThat(getAllAuditTaskLogs()).hasSize(0);
  }
Пример #22
0
 @Test
 public void indexType() {
   BlockBasedTableConfig blockBasedTableConfig = new BlockBasedTableConfig();
   assertThat(IndexType.values().length).isEqualTo(2);
   blockBasedTableConfig.setIndexType(IndexType.kHashSearch);
   assertThat(blockBasedTableConfig.indexType().equals(IndexType.kHashSearch));
   assertThat(IndexType.valueOf("kBinarySearch")).isNotNull();
   blockBasedTableConfig.setIndexType(IndexType.valueOf("kBinarySearch"));
   assertThat(blockBasedTableConfig.indexType().equals(IndexType.kBinarySearch));
 }
Пример #23
0
  private void testDeleteLogsByDateRange(Date startDate, Date endDate, boolean remove) {
    processInstanceList = new ArrayList<ProcessInstance>();
    kieSession = createKSession(HUMAN_TASK);

    processInstanceList.addAll(startProcess(kieSession, HUMAN_TASK_ID, 5));

    // Delete tasks created from date1 to date2.
    int resultCount = deleteAuditTaskInstanceLogs(startDate, endDate);
    Assertions.assertThat(resultCount).isEqualTo(remove ? 5 : 0);
    Assertions.assertThat(getAllAuditTaskLogs()).hasSize(remove ? 0 : 5);
  }
  // 验证删除
  @Test
  @DataSet("validate-AuthoritySetting.xls")
  public void validateDelete() {
    String ids = "1";
    String flag = smsAuthoritySettingManager.validateDelete(ids);
    assertThat(flag.equals("不可删除已启用的网关"));

    ids = "2";
    flag = smsAuthoritySettingManager.validateDelete(ids);
    assertThat(flag.equals(""));
  }
  @Test
  public void testThatTemplateIsAdded() throws Exception {
    GetIndexTemplatesResponse response =
        client().admin().indices().prepareGetTemplates("metrics_template").get();

    org.assertj.core.api.Assertions.assertThat(response.getIndexTemplates()).hasSize(1);
    IndexTemplateMetaData templateData = response.getIndexTemplates().get(0);
    org.assertj.core.api.Assertions.assertThat(templateData.order()).isEqualTo(0);
    org.assertj.core.api.Assertions.assertThat(templateData.getMappings().get("_default_"))
        .isNotNull();
  }
Пример #26
0
  @Test
  public void should_have_a_valid_url() {
    org.assertj.core.api.Assertions.assertThat(ITEM.hasValidURL()).isTrue();

    PODCAST.setType("send");
    ITEM.setUrl("");
    org.assertj.core.api.Assertions.assertThat(ITEM.hasValidURL()).isTrue();

    PODCAST.setType("Youtube");
    ITEM.setUrl("");
    org.assertj.core.api.Assertions.assertThat(ITEM.hasValidURL()).isFalse();
  }
  @Test
  public void testAssemblingWithModelMapper() {
    Category category = factory.createCategory(1L, "category1", "http://img.png");
    // Specify to use the default assembler based on ModelMapper
    // Passing the ModelMapper.class qualifier is the same that using AssemblerTypes.MODEL_MAPPER
    CategoryRepresentation representation =
        fluently.assemble(category).with(ModelMapper.class).to(CategoryRepresentation.class);

    Assertions.assertThat(representation.getId()).isEqualTo(1L);
    Assertions.assertThat(representation.getName()).isEqualTo("category1");
    Assertions.assertThat(representation.getUrlImg()).isEqualTo("http://img.png");
  }
  @Test
  public void testThatPercolationNotificationWorks() throws IOException, InterruptedException {
    SimpleNotifier notifier = new SimpleNotifier();

    MetricFilter percolationFilter =
        new MetricFilter() {
          @Override
          public boolean matches(String name, Metric metric) {
            return name.startsWith(prefix + ".foo");
          }
        };
    elasticsearchReporter =
        createElasticsearchReporterBuilder()
            .percolationFilter(percolationFilter)
            .percolationNotifier(notifier)
            .build();

    final Counter evictions = registry.counter("foo");
    evictions.inc(18);
    reportAndRefresh();

    QueryBuilder queryBuilder =
        QueryBuilders.boolQuery()
            .must(QueryBuilders.matchAllQuery())
            .filter(
                QueryBuilders.boolQuery()
                    .must(QueryBuilders.rangeQuery("count").gte(20))
                    .must(QueryBuilders.termQuery("name", prefix + ".foo")));
    String json = String.format("{ \"query\" : %s }", queryBuilder.buildAsBytes().toUtf8());
    client()
        .prepareIndex(indexWithDate, ".percolator", "myName")
        .setRefresh(true)
        .setSource(json)
        .execute()
        .actionGet();

    evictions.inc(1);
    reportAndRefresh();
    assertThat(notifier.metrics.size(), is(0));

    evictions.inc(2);
    reportAndRefresh();
    org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(1);
    org.assertj.core.api.Assertions.assertThat(notifier.metrics).containsKey("myName");
    org.assertj.core.api.Assertions.assertThat(notifier.metrics.get("myName").name())
        .isEqualTo(prefix + ".foo");

    notifier.metrics.clear();
    evictions.dec(2);
    reportAndRefresh();
    org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(0);
  }
  @Test
  public void adaptedAuthenticationExceptionShouldHaveSameDetailMessage() {

    // Given
    AuthException authException = new AuthException("MESSAGE");

    // When
    AuthenticationException authenticationException = JaspiAdapters.adapt(authException);

    // Then
    Assertions.assertThat(authenticationException.getMessage()).isEqualTo("MESSAGE");
    Assertions.assertThat(authenticationException.getCause()).isNull();
  }
Пример #30
0
  @Test
  public void testFirstResult() {
    startHumanTaskProcess(6, "john's task", "john");

    List<TaskSummary> taskList =
        ejb.getTasksAssignedAsPotentialOwner(
            "john", null, null, new QueryFilter(2, 2, "t.name", true));
    logger.info("### Potential owner task list: " + taskList);
    Assertions.assertThat(taskList).hasSize(2);
    for (int i = 0; i < taskList.size(); i++) {
      Assertions.assertThat(taskList.get(i).getName()).isEqualTo("john's task " + (i + 1 + 2));
    }
  }