You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2017/12/19 14:07:15 UTC

[2/3] jclouds git commit: wip

wip


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/f4250d1b
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/f4250d1b
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/f4250d1b

Branch: refs/heads/keystonev3
Commit: f4250d1b68edb84229f05d05ffd4fc7b4d1d809c
Parents: 278ecf5
Author: Andrea Turli <an...@gmail.com>
Authored: Tue Dec 12 09:39:30 2017 +0100
Committer: Andrea Turli <an...@gmail.com>
Committed: Tue Dec 12 09:39:30 2017 +0100

----------------------------------------------------------------------
 .../keystone/v3/features/TokenApiLiveTest.java  | 55 ++++++++++++++++++
 .../keystone/v3/features/TokenApiMockTest.java  | 61 ++++++++++++++++++++
 2 files changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/f4250d1b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiLiveTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiLiveTest.java
new file mode 100644
index 0000000..8799efa
--- /dev/null
+++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiLiveTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.keystone.v3.features;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.openstack.keystone.auth.filters.AuthenticateRequest;
+import org.jclouds.openstack.keystone.v3.KeystoneApi;
+import org.jclouds.openstack.keystone.v3.internal.BaseV3KeystoneApiLiveTest;
+import org.testng.annotations.Test;
+
+import java.util.Properties;
+
+@Test(groups = "live", testName = "TokenApiLiveTest")
+public class TokenApiLiveTest extends BaseV3KeystoneApiLiveTest {
+
+   protected String token;
+
+   @Override
+   protected KeystoneApi create(Properties props, Iterable<Module> modules) {
+      Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
+      grabToken(injector.getInstance(AuthenticateRequest.class));
+      return injector.getInstance(KeystoneApi.class);
+   }
+
+   // Get the token currently in use
+   private void grabToken(AuthenticateRequest ar) {
+      HttpRequest test = ar.filter(HttpRequest.builder().method("GET").endpoint(endpoint).build());
+      token = Iterables.getOnlyElement(test.getHeaders().get("X-Auth-Token"));
+   }
+
+   public void testGetToken() {
+      System.out.println(api().get(token));
+   }
+
+   private TokenApi api() {
+      return api.getTokenApi();
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds/blob/f4250d1b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiMockTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiMockTest.java
new file mode 100644
index 0000000..ff64eb3
--- /dev/null
+++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/TokenApiMockTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.openstack.keystone.v3.features;
+
+import java.util.Map;
+
+import org.jclouds.openstack.keystone.v3.domain.Token;
+import org.jclouds.openstack.keystone.v3.internal.BaseV3KeystoneApiMockTest;
+import org.testng.annotations.Test;
+
+import com.google.common.reflect.TypeToken;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+@Test(groups = "unit", testName = "TokenApiMockTest", singleThreaded = true)
+public class TokenApiMockTest extends BaseV3KeystoneApiMockTest {
+
+   public void testGetToken() throws InterruptedException {
+      server.enqueue(jsonResponse("/v3/token.json").addHeader("X-Subject-Token", "bf583aefb74e45108346b4c1c8527a10"));
+
+      Token token = api.getTokenApi().get("bf583aefb74e45108346b4c1c8527a10");
+
+      assertEquals(token, tokenFromResource("/v3/token.json"));
+
+      assertEquals(server.getRequestCount(), 1);
+      assertSent(server, "GET", "/token/bf583aefb74e45108346b4c1c8527a10");
+   }
+
+   public void testGetTokenReturns404() throws InterruptedException {
+      server.enqueue(response404());
+
+      Token token = api.getTokenApi().get("bf583aefb74e45108346b4c1c8527a10");
+
+      assertNull(token);
+
+      assertEquals(server.getRequestCount(), 2);
+      assertSent(server, "POST", "/auth/tokens");
+      assertSent(server, "GET", "/token/bf583aefb74e45108346b4c1c8527a10");
+   }
+   
+   private Token tokenFromResource(String resource) {
+      return onlyObjectFromResource(resource, new TypeToken<Map<String, Token>>() {
+         private static final long serialVersionUID = 1L;
+      });
+   }
+}