@Test(enabled = false, expectedExceptions = BadRequestException.class)
  public void shouldNotCreateDuplicateResourceSetWithSameId() throws Exception {

    // Given
    OAuth2Request request = mock(OAuth2Request.class);
    ResourceSetDescription resourceSetDescription =
        new ResourceSetDescription(
            "RESOURCE_SET_ID",
            "CLIENT_ID",
            "RESOURCE_OWNER_ID",
            Collections.<String, Object>singletonMap("name", "RESOURCE_SET_NAME"));

    resourceSetDescription.setRealm("REALM");
    given(dataStore.query(Matchers.<QueryFilter<String>>anyObject()))
        .willReturn(Collections.singleton(resourceSetDescription));

    // When
    try {
      store.create(request, resourceSetDescription);
    } catch (BadRequestException e) {
      // Then
      assertThat(resourceSetDescription.getPolicyUri()).isNull();
      verify(dataStore, never()).create(any(ResourceSetDescription.class));
      throw e;
    }
  }
  @Test
  public void shouldDeleteResourceSetToken() throws Exception {

    // Given
    ResourceSetDescription resourceSetDescription =
        new ResourceSetDescription(
            "RESOURCE_SET_ID",
            "CLIENT_ID",
            "RESOURCE_OWNER_ID",
            Collections.<String, Object>emptyMap());

    resourceSetDescription.setRealm("REALM");

    given(
            dataStore.query(
                QueryFilter.and(
                    QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, "RESOURCE_SET_ID"),
                    QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM"))))
        .willReturn(Collections.singleton(resourceSetDescription));

    // When
    store.delete("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");

    // Then
    verify(dataStore).delete("RESOURCE_SET_ID");
  }
  @Test
  public void shouldQueryResourceSetToken() throws Exception {

    // Given
    Map<String, Object> queryParameters = new HashMap<String, Object>();
    queryParameters.put(ResourceSetTokenField.CLIENT_ID, "CLIENT_ID");
    ResourceSetDescription resourceSet1 =
        new ResourceSetDescription(
            "123", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());
    ResourceSetDescription resourceSet2 =
        new ResourceSetDescription(
            "456", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap());

    given(dataStore.query(Matchers.<QueryFilter<String>>anyObject()))
        .willReturn(asSet(resourceSet1, resourceSet2));
    resourceSet1.setRealm("REALM");
    resourceSet2.setRealm("REALM");

    // When
    QueryFilter<String> query = QueryFilter.alwaysTrue();
    Set<ResourceSetDescription> resourceSetDescriptions = store.query(query);

    // Then
    assertThat(resourceSetDescriptions).contains(resourceSet1, resourceSet2);
    ArgumentCaptor<QueryFilter> tokenFilterCaptor = ArgumentCaptor.forClass(QueryFilter.class);
    verify(dataStore).query(tokenFilterCaptor.capture());
    assertThat(tokenFilterCaptor.getValue())
        .isEqualTo(
            QueryFilter.and(query, QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM")));
  }
  @Test
  public void shouldReadResourceSetToken() throws Exception {

    // Given
    ResourceSetDescription resourceSetDescription =
        new ResourceSetDescription(
            "RESOURCE_SET_ID",
            "CLIENT_ID",
            "RESOURCE_OWNER_ID",
            Collections.<String, Object>emptyMap());

    given(
            dataStore.query(
                QueryFilter.and(
                    QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_SET_ID, "RESOURCE_SET_ID"),
                    QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM"))))
        .willReturn(Collections.singleton(resourceSetDescription));

    // When
    ResourceSetDescription readResourceSetDescription =
        store.read("RESOURCE_SET_ID", "RESOURCE_OWNER_ID");

    // Then
    assertThat(readResourceSetDescription).isEqualTo(readResourceSetDescription);
  }
  @Test
  public void shouldCreateResourceSetToken() throws Exception {

    // Given
    OAuth2Request request = mock(OAuth2Request.class);
    ResourceSetDescription resourceSetDescription =
        new ResourceSetDescription(
            "RESOURCE_SET_ID",
            "CLIENT_ID",
            "RESOURCE_OWNER_ID",
            Collections.<String, Object>singletonMap("name", "RESOURCE_SET_NAME"));

    given(dataStore.query(Matchers.<QueryFilter<String>>anyObject()))
        .willReturn(Collections.<ResourceSetDescription>emptySet());

    // When
    store.create(request, resourceSetDescription);

    // Then
    assertThat(resourceSetDescription.getPolicyUri()).isEqualTo("POLICY_URI");
    verify(dataStore).create(resourceSetDescription);
  }