incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1050663 [2/2] - in /incubator/amber/trunk/oauth-2.0/oauth2-common: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/amber/ src/main/java/org/apache/amber/oauth2/ src/main/java/org/apach...
Date Sat, 18 Dec 2010 16:38:37 GMT
Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,77 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.codehaus.jettison.AbstractXMLStreamReader;
+import org.codehaus.jettison.json.JSONObject;
+import org.codehaus.jettison.mapped.MappedXMLStreamReader;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+
+import org.apache.amber.oauth2.common.utils.JSONUtils;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class OAuthUtilsTest extends Assert {
+
+    @Test
+    public void testBuildJSON() throws Exception {
+        Map<String, String> params = new HashMap<String, String>();
+        params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST);
+
+        String json = JSONUtils.buildJSON(params);
+
+        JSONObject obj = new JSONObject(json);
+
+        AbstractXMLStreamReader reader = new MappedXMLStreamReader(obj);
+
+        assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        assertEquals(OAuthError.OAUTH_ERROR, reader.getName().getLocalPart());
+
+        assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, reader.getText());
+        assertEquals(XMLStreamReader.CHARACTERS, reader.next());
+        assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
+        assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
+
+    }
+
+    @Test
+    public void testEncodeOAuthHeader() throws Exception {
+
+        Map<String, String> entries = new HashMap<String, String>();
+        entries.put("realm", "Some Example Realm");
+        entries.put("error", "invalid_token");
+
+        String header = OAuthUtils.encodeOAuthHeader(entries);
+        assertEquals("OAuth error=\"invalid_token\",realm=\"Some Example Realm\"", header);
+
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/OAuthUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,55 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.message;
+
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class OAuthResponseTest {
+
+
+    @Test
+    public void testErrorResponse() throws Exception {
+        OAuthResponse oAuthResponse = OAuthResponse.errorResponse(400)
+            .setError("error")
+            .setRealm("album")
+            .setState("ok")
+            .setErrorDescription("error_description")
+            .setErrorUri("http://example-uri")
+            .setParam("param", "value")
+            .buildJSONMessage();
+
+        String body = oAuthResponse.getBody();
+        Assert.assertEquals(
+            "{\"error_uri\":\"http:\\/\\/example-uri\",\"error\":\"error\",\"param\":\"value\","
+                + "\"realm\":\"album\",\"state\":\"ok\",\"error_description\":\"error_description\"}",
+            body);
+    }
+
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/message/OAuthResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,72 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.parameters;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.amber.oauth2.common.utils.DummyOAuthMessage;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.message.OAuthMessage;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class BodyURLEncodedParametersApplierTest {
+
+    @Test
+    public void testApplyOAuthParameters() throws Exception {
+
+        OAuthParametersApplier app = new BodyURLEncodedParametersApplier();
+
+        Map<String, String> params = new HashMap<String, String>();
+        params.put(OAuth.OAUTH_EXPIRES_IN, "3600");
+        params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz");
+        params.put(OAuth.OAUTH_CODE, "code_");
+        params.put(OAuth.OAUTH_SCOPE, "read");
+        params.put(OAuth.OAUTH_STATE, "state");
+        params.put("empty_param", "");
+        params.put("null_param", null);
+        params.put("", "some_value");
+        params.put(null, "some_value");
+
+        OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);
+
+        app.applyOAuthParameters(message, params);
+
+        String body = message.getBody();
+        Assert.assertTrue(body.contains("3600"));
+        Assert.assertTrue(body.contains("token_authz"));
+        Assert.assertTrue(body.contains("code_"));
+        Assert.assertTrue(body.contains("read"));
+        Assert.assertTrue(body.contains("state"));
+
+        Assert.assertFalse(body.contains("empty_param"));
+        Assert.assertFalse(body.contains("null_param"));
+
+
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/BodyURLEncodedParametersApplierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,72 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.parameters;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.message.OAuthMessage;
+import org.apache.amber.oauth2.common.utils.DummyOAuthMessage;
+import org.apache.amber.oauth2.common.utils.JSONUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class JSONBodyParametersApplierTest {
+
+    @Test
+    public void testApplyOAuthParameters() throws Exception {
+
+        OAuthParametersApplier app = new JSONBodyParametersApplier();
+
+        Map<String, String> params = new HashMap<String, String>();
+        params.put(OAuth.OAUTH_EXPIRES_IN, "3600");
+        params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz");
+        params.put(OAuth.OAUTH_CODE, "code_");
+        params.put(OAuth.OAUTH_SCOPE, "read");
+        params.put(OAuth.OAUTH_STATE, "state");
+        params.put("empty_param", "");
+        params.put("null_param", null);
+        params.put("", "some_value");
+        params.put(null, "some_value");
+
+        OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);
+        app.applyOAuthParameters(message, params);
+
+        String msgBody = message.getBody();
+        Map<String, String> map = JSONUtils.parseJSON(msgBody);
+        Assert.assertEquals("3600", map.get(OAuth.OAUTH_EXPIRES_IN));
+        Assert.assertEquals("token_authz", map.get(OAuth.OAUTH_ACCESS_TOKEN));
+        Assert.assertEquals("code_", map.get(OAuth.OAUTH_CODE));
+        Assert.assertEquals("read", map.get(OAuth.OAUTH_SCOPE));
+        Assert.assertEquals("state", map.get(OAuth.OAUTH_STATE));
+        Assert.assertNull(map.get("empty_param"));
+        Assert.assertNull(map.get("null_param"));
+        Assert.assertNull(map.get(""));
+        Assert.assertNull(map.get(null));
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/JSONBodyParametersApplierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,70 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.parameters;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.utils.DummyOAuthMessage;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.message.OAuthMessage;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class QueryParameterApplierTest {
+
+    @Test
+    public void testApplyOAuthParameters() throws Exception {
+
+        OAuthParametersApplier app = new QueryParameterApplier();
+
+        Map<String, String> params = new HashMap<String, String>();
+        params.put(OAuth.OAUTH_EXPIRES_IN, "3600");
+        params.put(OAuth.OAUTH_ACCESS_TOKEN, "token_authz");
+        params.put(OAuth.OAUTH_CODE, "code_");
+        params.put(OAuth.OAUTH_SCOPE, "read");
+        params.put(OAuth.OAUTH_STATE, "state");
+        params.put("empty_param", "");
+        params.put("null_param", null);
+
+        OAuthMessage message = new DummyOAuthMessage("http://www.example.com/rd", 200);
+
+        app.applyOAuthParameters(message, params);
+
+        String locationURI = message.getLocationUri();
+        Assert.assertTrue(locationURI.contains("3600"));
+        Assert.assertTrue(locationURI.contains("token_authz"));
+        Assert.assertTrue(locationURI.contains("code_"));
+        Assert.assertTrue(locationURI.contains("read"));
+        Assert.assertTrue(locationURI.contains("state"));
+
+        Assert.assertTrue(!locationURI.contains("empty_param"));
+        Assert.assertTrue(!locationURI.contains("null_param"));
+
+
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/QueryParameterApplierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,67 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.parameters;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+import org.apache.amber.oauth2.common.parameters.OAuthParametersApplier;
+import org.apache.amber.oauth2.common.parameters.WWWAuthHeaderParametersApplier;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.OAuth;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class WWWAuthHeaderParametersApplierTest {
+
+    @Test
+    public void testApplyOAuthParameters() throws Exception {
+
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("error", "invalid_token");
+        params.put("error_uri", "http://www.example.com/error");
+        params.put("scope", "s1 s2 s3");
+        params.put("empty_param", "");
+        params.put("null_param", null);
+        params.put("", "some_value");
+        params.put(null, "some_value");
+
+        OAuthResponse res = OAuthResponse.status(200).location("").buildQueryMessage();
+
+        OAuthParametersApplier applier = new WWWAuthHeaderParametersApplier();
+        res = (OAuthResponse)applier.applyOAuthParameters(res, params);
+        Assert.assertNotNull(res);
+        String header = res.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE);
+        Assert.assertNotNull(header);
+        Assert.assertEquals(OAuth.OAUTH_HEADER_NAME
+            + " scope=\"s1 s2 s3\",error_uri=\"http://www.example.com/error\",error=\"invalid_token\"",
+            header);
+
+
+    }
+
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/parameters/WWWAuthHeaderParametersApplierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,37 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.utils;
+
+import org.apache.amber.oauth2.common.message.OAuthResponse;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class DummyOAuthMessage extends OAuthResponse {
+
+
+    public DummyOAuthMessage(String uri, int responseStatus) {
+        super(uri, responseStatus);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/DummyOAuthMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,77 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.amber.oauth2.common.error.OAuthError;
+import org.apache.amber.oauth2.common.utils.JSONUtils;
+import org.codehaus.jettison.AbstractXMLStreamReader;
+import org.codehaus.jettison.json.JSONObject;
+import org.codehaus.jettison.mapped.MappedXMLStreamReader;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class JSONUtilsTest {
+
+    @Test
+    public void testBuildJSON() throws Exception {
+
+        Map<String, String> params = new HashMap<String, String>();
+        params.put(OAuthError.OAUTH_ERROR, OAuthError.TokenResponse.INVALID_REQUEST);
+
+        String json = JSONUtils.buildJSON(params);
+
+        JSONObject obj = new JSONObject(json);
+
+        AbstractXMLStreamReader reader = new MappedXMLStreamReader(obj);
+
+        Assert.assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
+        Assert.assertEquals(OAuthError.OAUTH_ERROR, reader.getName().getLocalPart());
+
+        Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, reader.getText());
+        Assert.assertEquals(XMLStreamReader.CHARACTERS, reader.next());
+        Assert.assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
+        Assert.assertEquals(XMLStreamReader.END_DOCUMENT, reader.next());
+
+    }
+
+    @Test
+    public void testParseJson() throws Exception {
+        Map<String, String> jsonParams = new HashMap<String, String>();
+        jsonParams.put("author", "John B. Smith");
+        jsonParams.put("year", "2000");
+
+        String s = JSONUtils.buildJSON(jsonParams);
+        Map<String, String> map = JSONUtils.parseJSON(s);
+        Assert.assertEquals("John B. Smith", map.get("author"));
+        Assert.assertEquals("2000", map.get("year"));
+
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/JSONUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,180 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.utils.OAuthUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.apache.amber.oauth2.common.OAuth;
+
+import org.apache.amber.oauth2.common.error.OAuthError;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class OAuthUtilsTest {
+    @Test
+    public void testFormat() throws Exception {
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put("movie", "Kiler");
+        parameters.put("director", "Machulski");
+
+
+        String format = OAuthUtils.format(parameters.entrySet(), "UTF-8");
+        Assert.assertEquals("movie=Kiler&director=Machulski", format);
+    }
+
+    @Test
+    public void testSaveStreamAsString() throws Exception {
+        String sampleTest = "It is raining again today";
+
+        InputStream is = new ByteArrayInputStream(sampleTest.getBytes("UTF-8"));
+        Assert.assertEquals(sampleTest, OAuthUtils.saveStreamAsString(is));
+    }
+
+    @Test
+    public void testHandleOAuthProblemException() throws Exception {
+        OAuthProblemException exception = OAuthUtils.handleOAuthProblemException("missing
parameter");
+
+        Assert.assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, exception.getError());
+        Assert.assertEquals("missing parameter", exception.getDescription());
+    }
+
+    @Test
+    public void testHandleMissingParameters() throws Exception {
+        Set<String> missingParameters = new HashSet<String>();
+        missingParameters.add(OAuth.OAUTH_CLIENT_ID);
+        missingParameters.add(OAuth.OAUTH_CLIENT_SECRET);
+
+        OAuthUtils.handleMissingParameters(missingParameters);
+    }
+
+    @Test
+    public void testHandleNotAllowedParametersOAuthException() throws Exception {
+
+    }
+
+    @Test
+    public void testDecodeForm() throws Exception {
+
+    }
+
+    @Test
+    public void testIsFormEncoded() throws Exception {
+
+    }
+
+    @Test
+    public void testDecodePercent() throws Exception {
+
+    }
+
+    @Test
+    public void testPercentEncode() throws Exception {
+
+    }
+
+    @Test
+    public void testInstantiateClass() throws Exception {
+
+    }
+
+    @Test
+    public void testInstantiateClassWithParameters() throws Exception {
+
+    }
+
+    @Test
+    public void testGetAuthHeaderField() throws Exception {
+
+    }
+
+    @Test
+    public void testDecodeOAuthHeader() throws Exception {
+
+    }
+
+    @Test
+    public void testEncodeOAuthHeader() throws Exception {
+
+    }
+
+    @Test
+    public void testIsEmpty() throws Exception {
+
+    }
+
+    @Test
+    public void testHasEmptyValues() throws Exception {
+
+    }
+
+    @Test
+    public void testGetAuthzMethod() throws Exception {
+
+    }
+
+    @Test
+    public void testHandleOAuthError() throws Exception {
+
+    }
+
+    @Test
+    public void testDecodeScopes() throws Exception {
+
+    }
+
+    @Test
+    public void testEncodeScopes() throws Exception {
+
+    }
+
+    @Test
+    public void testIsExpired() throws Exception {
+
+    }
+
+    @Test
+    public void testGetIssuedTimeInSec() throws Exception {
+
+    }
+
+    @Test
+    public void testIsMultipart() throws Exception {
+
+    }
+
+    @Test
+    public void testHasContentType() throws Exception {
+
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/utils/OAuthUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,59 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.validators;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.validators.AbstractValidator;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class AbstractValidatorImpl extends AbstractValidator {
+
+    public void validateMethod(HttpServletRequest request) throws OAuthProblemException {
+        super.validateMethod(request);
+    }
+
+    public void validateContentType(HttpServletRequest request) throws OAuthProblemException
{
+        super.validateContentType(request);
+    }
+
+    public void validateRequiredParameters(HttpServletRequest request) throws OAuthProblemException
{
+        super.validateRequiredParameters(request);
+    }
+
+    public void validateOptionalParameters(HttpServletRequest request) throws OAuthProblemException
{
+        super.validateOptionalParameters(request);
+    }
+
+    public void validateNotAllowedParameters(HttpServletRequest request) throws OAuthProblemException
{
+        super.validateNotAllowedParameters(request);
+    }
+
+    public void performAllValidations(HttpServletRequest request) throws OAuthProblemException
{
+        super.performAllValidations(request);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java?rev=1050663&view=auto
==============================================================================
--- incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java
(added)
+++ incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java
Sat Dec 18 16:38:36 2010
@@ -0,0 +1,76 @@
+/**
+ *       Copyright 2010 Newcastle University
+ *
+ *          http://research.ncl.ac.uk/smart/
+ *
+ * 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.apache.amber.oauth2.common.validators;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * @author Maciej Machulak (m.p.machulak@ncl.ac.uk)
+ * @author Lukasz Moren (lukasz.moren@ncl.ac.uk)
+ * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk)
+ */
+public class AbstractValidatorTest {
+
+    @Test
+    public void testValidateContentType() throws Exception {
+
+        HttpServletRequest request = createStrictMock(HttpServletRequest.class);
+
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
+        replay(request);
+
+        AbstractValidator validator = new AbstractValidatorImpl();
+        validator.validateContentType(request);
+        verify(request);
+
+        reset(request);
+
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED + ";utf-8");
+        replay(request);
+
+        validator = new AbstractValidatorImpl();
+        validator.validateContentType(request);
+        verify(request);
+    }
+
+    @Test(expected = OAuthProblemException.class)
+    public void testInvalidContentType() throws Exception {
+        HttpServletRequest request = createStrictMock(HttpServletRequest.class);
+
+        expect(request.getContentType()).andStubReturn(OAuth.ContentType.JSON);
+        replay(request);
+
+        AbstractValidator validator = new AbstractValidatorImpl();
+        validator.validateContentType(request);
+        verify(request);
+    }
+}

Propchange: incubator/amber/trunk/oauth-2.0/oauth2-common/src/test/java/org/apache/amber/oauth2/common/validators/AbstractValidatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message