Exemplo n.º 1
0
  @Test
  public void getProxy_not_found() {
    when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32")))
        .thenThrow(EmptyResultDataAccessException.class);

    final Response response = subject.getProxy("10.0.0.0/32");
    assertThat(response.getStatus(), is(404));
  }
Exemplo n.º 2
0
  @Test
  public void getProxy() {
    final Proxy proxy = new Proxy("10.0.0.0/32", "test");
    when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32"))).thenReturn(proxy);

    final Response response = subject.getProxy("10.0.0.0/32");
    assertThat((Proxy) response.getEntity(), is(proxy));
  }
Exemplo n.º 3
0
  @Test
  public void getProxies() {
    List<Proxy> proxies = Lists.newArrayList(new Proxy());
    when(aclServiceDao.getProxies()).thenReturn(proxies);

    final List<Proxy> list = subject.getProxies();
    assertThat(list, is(proxies));
  }
Exemplo n.º 4
0
  @Test
  public void deleteProxy() {
    when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32")))
        .thenReturn(new Proxy("10.0.0.0/32", ""));

    final Response response = subject.deleteProxy("10.0.0.0/32");
    assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));

    verify(aclServiceDao).deleteProxy(IpInterval.parse("10.0.0.0/32"));
  }
Exemplo n.º 5
0
  @Test
  public void deleteProxy_unknown() {
    when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32")))
        .thenThrow(EmptyResultDataAccessException.class);

    final Response response = subject.deleteProxy("10.0.0.0/32");
    assertThat(response.getStatus(), is(Response.Status.NOT_FOUND.getStatusCode()));

    verify(aclServiceDao, never()).deleteProxy(Matchers.any(IpInterval.class));
  }
Exemplo n.º 6
0
  @Test
  public void saveProxy_modify() {
    when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32")))
        .thenReturn(new Proxy("10.0.0.0/32", ""));

    final Proxy proxy = new Proxy("10.0.0.0/32", "some");
    final Response response = subject.saveProxy(proxy);
    assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
    assertThat(response.getEntity(), instanceOf(Proxy.class));
    assertThat(((Proxy) response.getEntity()).getPrefix(), is("10.0.0.0/32"));

    verify(aclServiceDao).updateProxy(proxy);
  }
Exemplo n.º 7
0
  @Test
  public void saveProxy_create() {
    when(aclServiceDao.getProxy(IpInterval.parse("10.0.0.0/32")))
        .thenThrow(EmptyResultDataAccessException.class);

    final Proxy proxy = new Proxy("10.0.0.0/32", "some");
    final Response response = subject.saveProxy(proxy);
    assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
    assertThat(response.getEntity(), instanceOf(Proxy.class));
    assertThat(((Proxy) response.getEntity()).getPrefix(), is("10.0.0.0/32"));

    verify(aclServiceDao).createProxy(proxy);
  }