Example #1
0
  @Test(dependsOnMethods = "shouldGetById")
  public void shouldUpdateStack() throws Exception {
    final StackImpl stack = stacks[0];

    stack.setName("new-name");
    stack.setCreator("new-creator");
    stack.setDescription("new-description");
    stack.setScope("new-scope");
    stack.getTags().clear();
    stack.getTags().add("new-tag");

    // Remove an existing component
    stack.getComponents().remove(1);

    // Add a new component
    stack.getComponents().add(new StackComponentImpl("component3", "component3-version"));

    // Update an existing component
    final StackComponentImpl component = stack.getComponents().get(0);
    component.setName("new-name");
    component.setVersion("new-version");

    // Updating source
    final StackSourceImpl source = stack.getSource();
    source.setType("new-type");
    source.setOrigin("new-source");

    // Set a new icon
    stack.setStackIcon(new StackIcon("new-name", "new-media", "new-data".getBytes()));

    stackDao.update(stack);

    assertEquals(stackDao.getById(stack.getId()), new StackImpl(stack));
  }
Example #2
0
  @Test(dependsOnMethods = "shouldGetById")
  public void shouldCreateStack() throws Exception {
    final StackImpl stack = createStack("new-stack", "new-stack-name");

    stackDao.create(stack);

    assertEquals(stackDao.getById(stack.getId()), stack);
  }
Example #3
0
  @Test(
      expectedExceptions = NotFoundException.class,
      dependsOnMethods = "shouldThrowNotFoundExceptionWhenGettingNonExistingStack")
  public void shouldRemoveStack() throws Exception {
    final StackImpl stack = stacks[0];

    stackDao.remove(stack.getId());

    // Should throw an exception
    stackDao.getById(stack.getId());
  }
Example #4
0
  @Test(expectedExceptions = ConflictException.class)
  public void shouldThrowConflictExceptionWhenCreatingStackWithIdThatAlreadyExists()
      throws Exception {
    final StackImpl stack = createStack(stacks[0].getId(), "new-name");

    stackDao.create(stack);
  }
Example #5
0
  @Test(expectedExceptions = ConflictException.class)
  public void shouldThrowConflictExceptionWhenCreatingStackWithNameThatAlreadyExists()
      throws Exception {
    final StackImpl stack = createStack("new-stack-id", stacks[0].getName());

    stackDao.create(stack);
  }
Example #6
0
  @Test(expectedExceptions = ConflictException.class)
  public void shouldNotUpdateStackIfNewNameIsReserved() throws Exception {
    final StackImpl stack = stacks[0];
    stack.setName(stacks[1].getName());

    stackDao.update(stack);
  }
Example #7
0
  @Test
  public void shouldPublishStackPersistedEventAfterStackIsPersisted() throws Exception {
    final boolean[] isNotified = new boolean[] {false};
    eventService.subscribe(event -> isNotified[0] = true, StackPersistedEvent.class);

    stackDao.create(createStack("test", "test"));

    assertTrue(isNotified[0], "Event subscriber notified");
  }
Example #8
0
  @Test
  public void shouldReturnAllStacksWhenSearchingWithoutTags() throws Exception {
    final List<StackImpl> found = stackDao.searchStacks(null, null, 0, 0);
    found.forEach(s -> Collections.sort(s.getTags()));
    for (StackImpl stack : stacks) {
      Collections.sort(stack.getTags());
    }

    assertEquals(new HashSet<>(found), new HashSet<>(asList(stacks)));
  }
Example #9
0
  @Test(dependsOnMethods = "shouldUpdateStack")
  public void shouldFindStacksWithSpecifiedTags() throws Exception {
    stacks[0].getTags().addAll(asList("search-tag1", "search-tag2"));
    stacks[1].getTags().addAll(asList("search-tag1", "non-search-tag"));
    stacks[2].getTags().addAll(asList("non-search-tag", "search-tag2"));
    stacks[3].getTags().addAll(asList("search-tag1", "search-tag2", "another-tag"));
    updateAll();

    final List<StackImpl> found =
        stackDao.searchStacks(null, asList("search-tag1", "search-tag2"), 0, 0);
    found.forEach(s -> Collections.sort(s.getTags()));
    for (StackImpl stack : stacks) {
      Collections.sort(stack.getTags());
    }

    assertEquals(new HashSet<>(found), new HashSet<>(asList(stacks[0], stacks[3])));
  }
Example #10
0
 @Test(expectedExceptions = NullPointerException.class)
 public void shouldThrowNpeWhenUpdatingNullStack() throws Exception {
   stackDao.update(null);
 }
Example #11
0
 @Test(expectedExceptions = NullPointerException.class)
 public void shouldThrowNpeWhenGettingStackByNullKey() throws Exception {
   stackDao.getById(null);
 }
Example #12
0
 @Test(expectedExceptions = NotFoundException.class)
 public void shouldThrowNotFoundExceptionWhenGettingNonExistingStack() throws Exception {
   stackDao.getById("non-existing-stack");
 }
Example #13
0
  @Test
  public void shouldGetById() throws Exception {
    final StackImpl stack = stacks[0];

    assertEquals(stackDao.getById(stack.getId()), stack);
  }
Example #14
0
 private void updateAll() throws ConflictException, NotFoundException, ServerException {
   for (StackImpl stack : stacks) {
     stackDao.update(stack);
   }
 }
Example #15
0
 @Test(expectedExceptions = NotFoundException.class)
 public void shouldThrowNotFoundExceptionWhenUpdatingNonExistingStack() throws Exception {
   stackDao.update(createStack("new-stack", "new-stack-name"));
 }
Example #16
0
 @Test
 public void shouldNotThrowAnyExceptionWhenRemovingNonExistingStack() throws Exception {
   stackDao.remove("non-existing");
 }
Example #17
0
 @Test(expectedExceptions = NullPointerException.class)
 public void shouldThrowNpeWhenRemovingNull() throws Exception {
   stackDao.remove(null);
 }