You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/02/08 19:29:52 UTC
[15/32] ISIS-323: lots more refactoring of RO
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserReprRenderer.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserReprRenderer.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserReprRenderer.java
deleted file mode 100644
index f2bc2b5..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserReprRenderer.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 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.isis.viewer.restfulobjects.viewer.resources.user;
-
-import org.apache.isis.core.commons.authentication.AuthenticationSession;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.viewer.RendererContext;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.LinkFollower;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.ReprRenderer;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.ReprRendererAbstract;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.ReprRendererFactoryAbstract;
-
-public class UserReprRenderer extends ReprRendererAbstract<UserReprRenderer, AuthenticationSession> {
-
- public static class Factory extends ReprRendererFactoryAbstract {
-
- public Factory() {
- super(RepresentationType.USER);
- }
-
- @Override
- public ReprRenderer<?, ?> newRenderer(final RendererContext resourceContext, final LinkFollower linkFollower, final JsonRepresentation representation) {
- return new UserReprRenderer(resourceContext, linkFollower, getRepresentationType(), representation);
- }
- }
-
- private UserReprRenderer(final RendererContext resourceContext, final LinkFollower linkFollower, final RepresentationType representationType, final JsonRepresentation representation) {
- super(resourceContext, linkFollower, representationType, representation);
- }
-
- @Override
- public UserReprRenderer with(final AuthenticationSession authenticationSession) {
- representation.mapPut("userName", authenticationSession.getUserName());
- final JsonRepresentation roles = JsonRepresentation.newArray();
- for (final String role : authenticationSession.getRoles()) {
- roles.arrayAdd(role);
- }
- representation.mapPut("roles", roles);
- return this;
- }
-
- @Override
- public JsonRepresentation render() {
- if (includesSelf) {
- withSelf("user");
- }
- getExtensions();
- return representation;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserResourceServerside.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserResourceServerside.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserResourceServerside.java
deleted file mode 100644
index 8f629bc..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/user/UserResourceServerside.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.resources.user;
-
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.isis.applib.annotation.Where;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulMediaType;
-import org.apache.isis.viewer.restfulobjects.applib.user.UserResource;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.RendererFactory;
-import org.apache.isis.viewer.restfulobjects.viewer.resources.ResourceAbstract;
-
-public class UserResourceServerside extends ResourceAbstract implements UserResource {
-
- @Override
- @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_USER })
- public Response user() {
- final RepresentationType user = RepresentationType.USER;
- init(user, Where.NOWHERE);
-
- final RendererFactory factory = rendererFactoryRegistry.find(user);
- final UserReprRenderer renderer = (UserReprRenderer) factory.newRenderer(getResourceContext(), null, JsonRepresentation.newMap());
- renderer.includesSelf().with(getAuthenticationSession());
-
- return responseOfOk(renderer, Caching.ONE_HOUR).build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionReprRenderer.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionReprRenderer.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionReprRenderer.java
deleted file mode 100644
index 136ddf0..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionReprRenderer.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.resources.version;
-
-import java.nio.charset.Charset;
-
-import com.google.common.io.Resources;
-
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.viewer.RendererContext;
-import org.apache.isis.viewer.restfulobjects.viewer.RestfulObjectsApplication;
-import org.apache.isis.viewer.restfulobjects.viewer.ResourceContext;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.LinkFollower;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.ReprRenderer;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.ReprRendererAbstract;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.ReprRendererFactoryAbstract;
-
-public class VersionReprRenderer extends ReprRendererAbstract<VersionReprRenderer, Void> {
-
- private static final String META_INF_POM_PROPERTIES = "/META-INF/maven/org.apache.isis.viewer/restfulobjects-viewer/pom.properties";
-
- public static class Factory extends ReprRendererFactoryAbstract {
- public Factory() {
- super(RepresentationType.VERSION);
- }
-
- @Override
- public ReprRenderer<?, ?> newRenderer(final RendererContext resourceContext, final LinkFollower linkFollower, final JsonRepresentation representation) {
- return new VersionReprRenderer(resourceContext, linkFollower, getRepresentationType(), representation);
- }
- }
-
- private VersionReprRenderer(final RendererContext resourceContext, final LinkFollower linkFollower, final RepresentationType representationType, final JsonRepresentation representation) {
- super(resourceContext, linkFollower, representationType, representation);
- }
-
- @Override
- public VersionReprRenderer with(final Void t) {
- return this;
- }
-
- @Override
- public JsonRepresentation render() {
-
- if (includesSelf) {
- withSelf("version/");
- }
-
- representation.mapPut("specVersion", RestfulObjectsApplication.SPEC_VERSION);
- representation.mapPut("implVersion", versionFromManifest());
-
- putOptionalCapabilities();
- putExtensions();
-
- return representation;
- }
-
- private static String versionFromManifest() {
- try {
- return Resources.toString(Resources.getResource(META_INF_POM_PROPERTIES), Charset.defaultCharset());
- } catch (final Exception ex) {
- return "UNKNOWN";
- }
- }
-
- private void putOptionalCapabilities() {
- final JsonRepresentation optionalCapabilities = JsonRepresentation.newMap();
-
- optionalCapabilities.mapPut("concurrencyChecking", "no");
- optionalCapabilities.mapPut("transientObjects", "yes");
- optionalCapabilities.mapPut("deleteObjects", "no");
- optionalCapabilities.mapPut("simpleArguments", "no");
- optionalCapabilities.mapPut("partialArguments", "no");
- optionalCapabilities.mapPut("followLinks", "yes");
- optionalCapabilities.mapPut("validateOnly", "no");
- optionalCapabilities.mapPut("pagination", "no");
- optionalCapabilities.mapPut("sorting", "no");
- optionalCapabilities.mapPut("domainModel", "rich");
-
- representation.mapPut("optionalCapabilities", optionalCapabilities);
- }
-
- private void putExtensions() {
- representation.mapPut("extensions", JsonRepresentation.newMap());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionResourceServerside.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionResourceServerside.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionResourceServerside.java
deleted file mode 100644
index e0d8680..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/resources/version/VersionResourceServerside.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.resources.version;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.isis.applib.annotation.Where;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulMediaType;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulResponse.HttpStatusCode;
-import org.apache.isis.viewer.restfulobjects.applib.version.VersionResource;
-import org.apache.isis.viewer.restfulobjects.viewer.RestfulObjectsApplicationException;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.RendererFactory;
-import org.apache.isis.viewer.restfulobjects.viewer.resources.ResourceAbstract;
-
-/**
- * Implementation note: it seems to be necessary to annotate the implementation
- * with {@link Path} rather than the interface (at least under RestEasy 1.0.2
- * and 1.1-RC2).
- */
-@Path("/version")
-public class VersionResourceServerside extends ResourceAbstract implements VersionResource {
-
- @Override
- @GET
- @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_VERSION })
- public Response version() {
- final RepresentationType representationType = RepresentationType.VERSION;
-
- init(representationType, Where.NOWHERE);
- fakeRuntimeExceptionIfXFail();
-
- final RendererFactory factory = rendererFactoryRegistry.find(representationType);
- final VersionReprRenderer renderer = (VersionReprRenderer) factory.newRenderer(getResourceContext(), null, JsonRepresentation.newMap());
- renderer.includesSelf();
-
- return responseOfOk(renderer, Caching.ONE_DAY).build();
- }
-
- private void fakeRuntimeExceptionIfXFail() {
- final HttpHeaders httpHeaders = getResourceContext().getHttpHeaders();
- if (httpHeaders.getRequestHeader("X-Fail") != null) {
- throw RestfulObjectsApplicationException.create(HttpStatusCode.METHOD_FAILURE);
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ActionUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ActionUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ActionUtils.java
deleted file mode 100644
index dafdb53..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ActionUtils.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import java.util.List;
-
-import com.google.common.collect.Lists;
-
-import org.apache.isis.core.metamodel.spec.ActionType;
-import org.apache.isis.core.metamodel.spec.ObjectActionSet;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
-
-public final class ActionUtils {
-
- private ActionUtils() {
- }
-
- public static List<ObjectAction> flattened(final List<ObjectAction> objectActions) {
- final List<ObjectAction> actions = Lists.newArrayList();
- for (final ObjectAction action : objectActions) {
- if (action.getType() == ActionType.SET) {
- final ObjectActionSet actionSet = (ObjectActionSet) action;
- final List<ObjectAction> subActions = actionSet.getActions();
- for (final ObjectAction subAction : subActions) {
- actions.add(subAction);
- }
- } else {
- actions.add(action);
- }
- }
- return actions;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/InputStreamUtil.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/InputStreamUtil.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/InputStreamUtil.java
deleted file mode 100644
index 35e8559..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/InputStreamUtil.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-public final class InputStreamUtil {
-
- private InputStreamUtil() {
- }
-
- public static List<String> getArgs(final InputStream body) {
- // will be sorted by arg
- final Map<String, String> args = new TreeMap<String, String>();
- if (body == null) {
- return listOfValues(args);
- }
- try {
- final InputStreamReader inputStreamReader = new InputStreamReader(body);
- final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- String readLine = bufferedReader.readLine();
- while (readLine != null) {
- final String[] keyValuePairs = readLine.split("&");
- for (final String keyValuePair : keyValuePairs) {
- final String[] keyThenValue = keyValuePair.split("=");
- args.put(keyThenValue[0], keyThenValue[1]);
- }
- readLine = bufferedReader.readLine();
- }
- return listOfValues(args);
- } catch (final IOException ex) {
- throw new RuntimeException(ex);
- }
- }
-
- private static ArrayList<String> listOfValues(final Map<String, String> args) {
- // returns the values in the order of the keys
- return new ArrayList<String>(args.values());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ListUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ListUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ListUtils.java
deleted file mode 100644
index 72036ac..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/ListUtils.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public final class ListUtils {
-
- private ListUtils() {
- }
-
- @SuppressWarnings("unchecked")
- public static <T> List<T> toList(final Object[] objects) {
- final List<T> list = new ArrayList<T>();
- for (final Object o : objects) {
- list.add((T) o);
- }
- return list;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/MapUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/MapUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/MapUtils.java
deleted file mode 100644
index 6c7a93a..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/MapUtils.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import java.util.Collections;
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-public final class MapUtils {
-
- /**
- * Returns an immutable map based on a list of key/value pairs.
- */
- public static Map<String, String> mapOf(final String... keyOrValues) {
- if (keyOrValues.length % 2 != 0) {
- throw new IllegalArgumentException("Must provide an even number of arguments");
- }
- final Map<String, String> map = Maps.newLinkedHashMap();
- String key = null;
- for (final String keyOrValue : keyOrValues) {
- if (key != null) {
- map.put(key, keyOrValue);
- key = null;
- } else {
- key = keyOrValue;
- }
- }
- return Collections.unmodifiableMap(map);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/OidUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/OidUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/OidUtils.java
deleted file mode 100644
index b160490..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/OidUtils.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.adapter.oid.Oid;
-import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
-import org.apache.isis.core.metamodel.adapter.oid.RootOid;
-import org.apache.isis.core.metamodel.adapter.oid.RootOidDefault;
-import org.apache.isis.viewer.restfulobjects.viewer.RendererContext;
-
-public final class OidUtils {
-
- private OidUtils() {
- }
-
- public static ObjectAdapter getObjectAdapter(final RendererContext resourceContext, final String oidEncodedStr) {
- final String oidStr = UrlDecoderUtils.urlDecode(oidEncodedStr);
- final RootOid rootOid = RootOidDefault.deStringEncoded(oidStr, getOidMarshaller());
- return resourceContext.getAdapterManager().adapterFor(rootOid);
- }
-
- public static String getOidStr(final RendererContext resourceContext, final ObjectAdapter objectAdapter) {
- final Oid oid = objectAdapter.getOid();
- if(!(oid instanceof RootOid)) {
- throw new IllegalArgumentException("objectAdapter must be a root adapter");
- }
- return oid != null ? oid.enString(getOidMarshaller()) : null;
- }
-
- protected static OidMarshaller getOidMarshaller() {
- return new OidMarshaller();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/PathUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/PathUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/PathUtils.java
deleted file mode 100644
index ff4cd83..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/PathUtils.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import javax.servlet.http.HttpServletRequest;
-
-public final class PathUtils {
-
- private PathUtils() {
- }
-
- public static String combine(final HttpServletRequest request, final String... pathElements) {
- final StringBuilder buf = new StringBuilder(request.getContextPath());
- for (final String pathElement : pathElements) {
- if (!pathElement.startsWith("/")) {
- buf.append("/");
- }
- buf.append(pathElement);
- }
- return buf.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/StringUtil.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/StringUtil.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/StringUtil.java
deleted file mode 100644
index 0c89548..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/StringUtil.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-public final class StringUtil {
-
- private StringUtil() {
- }
-
- public static String concat(final String... lines) {
- final StringBuilder buf = new StringBuilder();
- for (final String line : lines) {
- buf.append(line);
- }
- return buf.toString();
- }
-
- public static String quote(final String val) {
- return "\"" + val + "\"";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlDecoderUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlDecoderUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlDecoderUtils.java
deleted file mode 100644
index 718dbd5..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlDecoderUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-
-import javax.ws.rs.WebApplicationException;
-
-import org.apache.isis.viewer.restfulobjects.viewer.Constants;
-
-public final class UrlDecoderUtils {
-
- private UrlDecoderUtils() {
- }
-
- public static String urlDecode(final String oidStr) {
- try {
- return URLDecoder.decode(oidStr, Constants.URL_ENCODING_CHAR_SET);
- } catch (final UnsupportedEncodingException e) {
- throw new WebApplicationException(e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlParserUtils.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlParserUtils.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlParserUtils.java
deleted file mode 100644
index a597dd0..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/util/UrlParserUtils.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.util;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-
-public final class UrlParserUtils {
-
- private final static Pattern OBJECT_OID = Pattern.compile(".*objects\\/(.+)");;
- private final static Pattern DOMAIN_TYPE = Pattern.compile(".*domainTypes\\/([^/]+).*");;
-
- public final static String oidFromLink(final JsonRepresentation link) {
- final String href = link.getString("href");
- final Matcher matcher = OBJECT_OID.matcher(href);
- if (!matcher.matches()) {
- return null;
- }
- return matcher.group(1);
- }
-
- public final static String domainTypeFrom(final JsonRepresentation link) {
- return domainTypeFrom(link.getString("href"));
- }
-
- public static String domainTypeFrom(final String href) {
- final Matcher matcher = DOMAIN_TYPE.matcher(href);
- if (!matcher.matches()) {
- return null;
- }
- return matcher.group(1);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/webapp/PreProcessInterceptorForIsisSession.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/webapp/PreProcessInterceptorForIsisSession.java b/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/webapp/PreProcessInterceptorForIsisSession.java
deleted file mode 100644
index 1389a71..0000000
--- a/component/viewer/restfulobjects/impl/src/main/java/org/apache/isis/viewer/restfulobjects/viewer/webapp/PreProcessInterceptorForIsisSession.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.webapp;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.ext.Provider;
-
-import org.jboss.resteasy.annotations.interception.ServerInterceptor;
-import org.jboss.resteasy.core.ResourceMethod;
-import org.jboss.resteasy.core.ServerResponse;
-import org.jboss.resteasy.spi.Failure;
-import org.jboss.resteasy.spi.HttpRequest;
-import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
-
-@Provider
-@ServerInterceptor
-public class PreProcessInterceptorForIsisSession implements PreProcessInterceptor {
-
- @Override
- public ServerResponse preProcess(final HttpRequest request, final ResourceMethod method) throws Failure, WebApplicationException {
-
- // TODO Auto-generated method stub
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/site/apt/index.apt
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/site/apt/index.apt b/component/viewer/restfulobjects/impl/src/site/apt/index.apt
deleted file mode 100644
index 02e46ea..0000000
--- a/component/viewer/restfulobjects/impl/src/site/apt/index.apt
+++ /dev/null
@@ -1,27 +0,0 @@
-~~ 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.
-
-RestfulObjects for Isis Viewer
-
- The <viewer> module provides a set of JAX-RS resource implementations
- that serve up the domain objects as JSON representations.
-
-
-Further Info
-
- See this module's {{{./apidocs/index.html}Javadoc}} and the {{{../docbkx/html/guide/isis-restfulobjects-viewer.html}user guide}} for more information.
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/site/apt/jottings.apt
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/site/apt/jottings.apt b/component/viewer/restfulobjects/impl/src/site/apt/jottings.apt
deleted file mode 100644
index c5d1200..0000000
--- a/component/viewer/restfulobjects/impl/src/site/apt/jottings.apt
+++ /dev/null
@@ -1,24 +0,0 @@
-~~ 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.
-
-
-
-Jottings
-
- This page is to capture any random jottings relating to this module prior
- to being moved into formal documentation.
-
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/site/site.xml
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/site/site.xml b/component/viewer/restfulobjects/impl/src/site/site.xml
deleted file mode 100644
index 63e2551..0000000
--- a/component/viewer/restfulobjects/impl/src/site/site.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project name="${project.name}">
- <version position="right"/>
- <body>
- <breadcrumbs>
- <item name="Viewer" href="index.html"/>
- </breadcrumbs>
-
- <menu name="RestfulObjects for Isis">
- <item name="About" href="index.html" />
- <item name="Jottings" href="jottings.html" />
- </menu>
-
- <menu name="RestfulObjects Modules">
- <item name="Applib" href="../restfulobjects-applib/index.html" />
- <item name="Viewer" href="../restfulobjects-viewer/index.html" />
- </menu>
-
- <menu name="Maven Reports" ref="reports" />
- </body>
-</project>
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.java
deleted file mode 100644
index b42d6a5..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_ensureCompatibleAcceptHeader.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.applib.annotation.Where;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.viewer.RestfulObjectsApplicationException;
-import org.apache.isis.viewer.restfulobjects.viewer.ResourceContext;
-
-public class ResourceContextTest_ensureCompatibleAcceptHeader {
-
- private HttpHeaders httpHeaders;
- private HttpServletRequest httpServletRequest;
-
- private final Mockery context = new JUnit4Mockery();
-
- @Before
- public void setUp() throws Exception {
- httpHeaders = context.mock(HttpHeaders.class);
- httpServletRequest = context.mock(HttpServletRequest.class);
- context.checking(new Expectations() {
- {
- allowing(httpServletRequest).getQueryString();
- will(returnValue(""));
- }
- });
- }
-
- @Test
- public void noop() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(representationType.getMediaType()));
-
- instantiateResourceContext(representationType);
- }
-
- @Test
- public void happyCase() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(representationType.getMediaType()));
-
- instantiateResourceContext(representationType);
- }
-
- @Test
- public void acceptGenericAndProduceGeneric() throws Exception {
- final RepresentationType representationType = RepresentationType.GENERIC;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(MediaType.APPLICATION_JSON_TYPE));
-
- instantiateResourceContext(representationType);
- }
-
- @Test
- public void acceptGenericAndProduceSpecific() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(MediaType.APPLICATION_JSON_TYPE));
-
- instantiateResourceContext(representationType);
- }
-
- @Test(expected = RestfulObjectsApplicationException.class)
- public void nonMatching() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(MediaType.APPLICATION_ATOM_XML_TYPE));
-
- instantiateResourceContext(representationType);
- }
-
- @Test(expected = RestfulObjectsApplicationException.class)
- public void nonMatchingProfile() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(RepresentationType.USER.getMediaType()));
-
- instantiateResourceContext(representationType);
- }
-
- @Test(expected = RestfulObjectsApplicationException.class)
- public void nonMatchingProfile_ignoreGeneric() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList(RepresentationType.USER.getMediaType(), MediaType.APPLICATION_JSON_TYPE));
-
- instantiateResourceContext(representationType);
- }
-
- @Test(expected = RestfulObjectsApplicationException.class)
- public void emptyList() throws Exception {
- final RepresentationType representationType = RepresentationType.HOME_PAGE;
- givenHttpHeadersGetAcceptableMediaTypesReturns(Arrays.<MediaType> asList());
-
- instantiateResourceContext(representationType);
- }
-
- private void givenHttpHeadersGetAcceptableMediaTypesReturns(final List<MediaType> mediaTypes) {
- context.checking(new Expectations() {
- {
- one(httpHeaders).getAcceptableMediaTypes();
- will(returnValue(mediaTypes));
- }
- });
- }
-
- private ResourceContext instantiateResourceContext(final RepresentationType representationType) {
- return new ResourceContext(representationType, httpHeaders, null, null, httpServletRequest, null, null, null, null, null, null, null, null, null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_getArg.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_getArg.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_getArg.java
deleted file mode 100644
index 06eeea9..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/ResourceContextTest_getArg.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertThat;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.jmock.Expectations;
-import org.junit.Rule;
-import org.junit.Test;
-
-import org.apache.isis.core.unittestsupport.jmock.auto.Mock;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.RepresentationType;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulRequest.RequestParameter;
-import org.apache.isis.viewer.restfulobjects.applib.util.UrlEncodingUtils;
-import org.apache.isis.viewer.restfulobjects.viewer.ResourceContext;
-
-public class ResourceContextTest_getArg {
-
- @Rule
- public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
-
- @Mock
- private HttpServletRequest httpServletRequest;
- @Mock
- private ResourceContext resourceContext;
-
- private String queryString;
-
- @Test
- public void whenArgExists() throws Exception {
- queryString = UrlEncodingUtils.urlEncode(JsonRepresentation.newMap("x-ro-page", "123").asJsonNode());
-
- context.checking(new Expectations() {
- {
- one(httpServletRequest).getQueryString();
- will(returnValue(queryString));
- }
- });
- resourceContext = new ResourceContext(null, null, null, null, httpServletRequest, null, null, null, null, null, null, null, null, null) {
- @Override
- void init(final RepresentationType representationType) {
- //
- }
- };
- final Integer arg = resourceContext.getArg(RequestParameter.PAGE);
- assertThat(arg, equalTo(123));
- }
-
- @Test
- public void whenArgDoesNotExist() throws Exception {
- queryString = UrlEncodingUtils.urlEncode(JsonRepresentation.newMap("xxx", "123").asJsonNode());
-
- context.checking(new Expectations() {
- {
- one(httpServletRequest).getQueryString();
- will(returnValue(queryString));
- }
- });
- resourceContext = new ResourceContext(null, null, null, null, httpServletRequest, null, null, null, null, null, null, null, null, null) {
- @Override
- void init(final RepresentationType representationType) {
- //
- }
- };
- final Integer arg = resourceContext.getArg(RequestParameter.PAGE);
- assertThat(arg, equalTo(RequestParameter.PAGE.getDefault()));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/GraphTest_asGraph.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/GraphTest_asGraph.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/GraphTest_asGraph.java
deleted file mode 100644
index 0a05f81..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/GraphTest_asGraph.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.representations;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Test;
-
-import org.apache.isis.viewer.restfulobjects.applib.util.Parser;
-import org.apache.isis.viewer.restfulobjects.applib.util.PathNode;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.GraphUtil;
-
-@SuppressWarnings({ "rawtypes", "unchecked" })
-public class GraphTest_asGraph {
-
- @Test
- public void simple() throws Exception {
- final List<List<String>> links = asListOfLists("a.b.c,a.b.d,d.b,e,e");
- final Map<PathNode, Map> root = GraphUtil.asGraph(links);
-
- assertThat(root.size(), is(3));
- final Map<String, Map> nodeA = root.get(PathNode.parse("a"));
- assertThat(nodeA.size(), is(1));
- final Map<String, Map> nodeAB = nodeA.get(PathNode.parse("b"));
- assertThat(nodeAB.size(), is(2));
- final Map<String, Map> nodeABC = nodeAB.get(PathNode.parse("c"));
- assertThat(nodeABC.size(), is(0));
- final Map<String, Map> nodeABD = nodeAB.get(PathNode.parse("d"));
- assertThat(nodeABD.size(), is(0));
-
- final Map<String, Map> nodeD = root.get(PathNode.parse("d"));
- assertThat(nodeD.size(), is(1));
- final Map<String, Map> nodeDB = nodeD.get(PathNode.parse("b"));
- assertThat(nodeDB.size(), is(0));
-
- final Map<String, Map> nodeE = root.get(PathNode.parse("e"));
- assertThat(nodeE.size(), is(0));
- }
-
- @Test
- public void empty() throws Exception {
- final List<List<String>> links = asListOfLists("");
- final Map<PathNode, Map> root = GraphUtil.asGraph(links);
-
- assertThat(root.size(), is(0));
- }
-
- @Test
- public void whenNull() throws Exception {
- final Map<PathNode, Map> root = GraphUtil.asGraph(null);
-
- assertThat(root.size(), is(0));
- }
-
- private List<List<String>> asListOfLists(final String string) {
- return Parser.forListOfListOfStrings().valueOf(string);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/LinkFollowerTest_follow.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/LinkFollowerTest_follow.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/LinkFollowerTest_follow.java
deleted file mode 100644
index 039777f..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/representations/LinkFollowerTest_follow.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.representations;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Test;
-
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.util.Parser;
-import org.apache.isis.viewer.restfulobjects.viewer.representations.LinkFollower;
-
-public class LinkFollowerTest_follow {
-
- @Test
- public void simple() throws Exception {
- final List<List<String>> links = asListOfLists("a.b.c");
-
- final LinkFollower linkFollower = LinkFollower.create(links);
-
- assertThat(linkFollower.follow("a").isFollowing(), is(true));
- assertThat(linkFollower.follow("a").isTerminated(), is(false));
- }
-
- @Test
- public void notMatching() throws Exception {
- final List<List<String>> links = asListOfLists("a.b.c");
-
- final LinkFollower linkFollower = LinkFollower.create(links);
-
- assertThat(linkFollower.follow("x").isFollowing(), is(false));
- assertThat(linkFollower.follow("x").isTerminated(), is(true));
- }
-
- @Test
- public void create_noCriteria() throws Exception {
- final List<List<String>> links = asListOfLists("a.b.c");
-
- final LinkFollower linkFollower = LinkFollower.create(links);
-
- assertThat(linkFollower.criteria().size(), is(0));
- assertThat(linkFollower.matches(JsonRepresentation.newMap()), is(true));
- }
-
- @Test
- public void follow_noCriteria() throws Exception {
- final List<List<String>> links = asListOfLists("a.b.c");
-
- final LinkFollower linkFollower = LinkFollower.create(links);
-
- final LinkFollower followA = linkFollower.follow("a");
-
- assertThat(followA.criteria().size(), is(0));
- assertThat(linkFollower.matches(JsonRepresentation.newMap()), is(true));
- }
-
- @Test
- public void follow_withSingleCriteria() throws Exception {
- final List<List<String>> links = asListOfLists("a[x=y].b.c");
-
- final LinkFollower linkFollower = LinkFollower.create(links);
-
- assertThat(linkFollower.follow("x").isFollowing(), is(false));
-
- final LinkFollower followA = linkFollower.follow("a");
-
- assertThat(followA.isFollowing(), is(true));
- final Map<String, String> criteria = followA.criteria();
- assertThat(criteria.size(), is(1));
- assertThat(criteria.get("x"), is("y"));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "y")), is(true));
- assertThat(followA.matches(JsonRepresentation.newMap()), is(false));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "z")), is(false));
- }
-
- @Test
- public void follow_withMultipleCriteria() throws Exception {
- final List<List<String>> links = asListOfLists("a[x=y z=w].b.c");
-
- final LinkFollower linkFollower = LinkFollower.create(links);
-
- assertThat(linkFollower.follow("x").isFollowing(), is(false));
-
- final LinkFollower followA = linkFollower.follow("a");
-
- assertThat(followA.isFollowing(), is(true));
- final Map<String, String> criteria = followA.criteria();
- assertThat(criteria.size(), is(2));
-
- assertThat(criteria.get("x"), is("y"));
- assertThat(criteria.get("z"), is("w"));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "y", "z", "w")), is(true));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "y", "z", "w", "foo", "bar")), is(true));
- assertThat(followA.matches(JsonRepresentation.newMap()), is(false));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "y")), is(false));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "y", "foo", "bar")), is(false));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "bad")), is(false));
- assertThat(followA.matches(JsonRepresentation.newMap("x", "y", "z", "bad")), is(false));
- }
-
- private List<List<String>> asListOfLists(final String string) {
- return Parser.forListOfListOfStrings().valueOf(string);
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/JsonApplicationExceptionMapperTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/JsonApplicationExceptionMapperTest.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/JsonApplicationExceptionMapperTest.java
deleted file mode 100644
index ba3cfba..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/JsonApplicationExceptionMapperTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.resources;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
-
-import javax.ws.rs.core.Response;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.applib.RestfulResponse.HttpStatusCode;
-import org.apache.isis.viewer.restfulobjects.applib.util.JsonMapper;
-import org.apache.isis.viewer.restfulobjects.viewer.RestfulObjectsApplicationException;
-import org.apache.isis.viewer.restfulobjects.viewer.RestfulObjectsApplicationExceptionMapper;
-
-public class JsonApplicationExceptionMapperTest {
-
- private RestfulObjectsApplicationExceptionMapper exceptionMapper;
-
- @Before
- public void setUp() throws Exception {
- exceptionMapper = new RestfulObjectsApplicationExceptionMapper();
- }
-
- @Test
- public void simpleNoMessage() throws Exception {
-
- // given
- final HttpStatusCode status = HttpStatusCode.BAD_REQUEST;
- final RestfulObjectsApplicationException ex = RestfulObjectsApplicationException.create(status);
-
- // when
- final Response response = exceptionMapper.toResponse(ex);
-
- // then
- assertThat(HttpStatusCode.lookup(response.getStatus()), is(status));
- assertThat(response.getMetadata().get("Warning"), is(nullValue()));
-
- // and then
- final String entity = (String) response.getEntity();
- assertThat(entity, is(not(nullValue())));
- final JsonRepresentation jsonRepr = JsonMapper.instance().read(entity, JsonRepresentation.class);
-
- // then
- assertThat(jsonRepr.getString("message"), is(nullValue()));
- assertThat(jsonRepr.getArray("stackTrace"), is(not(nullValue())));
- assertThat(jsonRepr.getArray("stackTrace").size(), is(greaterThan(0)));
- assertThat(jsonRepr.getRepresentation("causedBy"), is(nullValue()));
- }
-
- @Test
- public void entity_withMessage() throws Exception {
-
- // givens
- final RestfulObjectsApplicationException ex = RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, "foobar");
-
- // when
- final Response response = exceptionMapper.toResponse(ex);
-
- // then
- assertThat((String) response.getMetadata().get("Warning").get(0), is(ex.getMessage()));
-
- // and then
- final String entity = (String) response.getEntity();
- assertThat(entity, is(not(nullValue())));
- final JsonRepresentation jsonRepr = JsonMapper.instance().read(entity, JsonRepresentation.class);
-
- // then
- assertThat(jsonRepr.getString("message"), is(ex.getMessage()));
- }
-
- @Test
- public void entity_withCause() throws Exception {
- // given
- final Exception cause = new Exception("barfoo");
- final RestfulObjectsApplicationException ex = RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, cause, "foobar");
-
- // when
- final Response response = exceptionMapper.toResponse(ex);
- final String entity = (String) response.getEntity();
- assertThat(entity, is(not(nullValue())));
- final JsonRepresentation jsonRepr = JsonMapper.instance().read(entity, JsonRepresentation.class);
-
- // then
- assertThat(jsonRepr.getString("message"), is(ex.getMessage()));
- final JsonRepresentation causedByRepr = jsonRepr.getRepresentation("causedBy");
- assertThat(causedByRepr, is(not(nullValue())));
- assertThat(causedByRepr.getString("message"), is(cause.getMessage()));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/DomainResourceHelperTest_readBodyAsMap.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/DomainResourceHelperTest_readBodyAsMap.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/DomainResourceHelperTest_readBodyAsMap.java
deleted file mode 100644
index 74083f9..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/DomainResourceHelperTest_readBodyAsMap.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.resources.domainobjects;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import org.junit.Test;
-
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.viewer.RestfulObjectsApplicationException;
-import org.apache.isis.viewer.restfulobjects.viewer.resources.domainobjects.DomainResourceHelper;
-
-public class DomainResourceHelperTest_readBodyAsMap {
-
- private JsonRepresentation representation;
-
- @Test
- public void whenNull() throws Exception {
- representation = DomainResourceHelper.readAsMap(null);
-
- assertThat(representation.isMap(), is(true));
- assertThat(representation.size(), is(0));
- }
-
- @Test
- public void whenEmptyString() throws Exception {
- representation = DomainResourceHelper.readAsMap("");
-
- assertThat(representation.isMap(), is(true));
- assertThat(representation.size(), is(0));
- }
-
- @Test
- public void whenWhitespaceOnlyString() throws Exception {
- representation = DomainResourceHelper.readAsMap(" \t ");
-
- assertThat(representation.isMap(), is(true));
- assertThat(representation.size(), is(0));
- }
-
- @Test
- public void emptyMap() throws Exception {
- representation = DomainResourceHelper.readAsMap("{}");
-
- assertThat(representation.isMap(), is(true));
- assertThat(representation.size(), is(0));
- }
-
- @Test
- public void map() throws Exception {
- representation = DomainResourceHelper.readAsMap("{\"foo\":\"bar\"}");
-
- assertThat(representation.isMap(), is(true));
- assertThat(representation.size(), is(1));
- }
-
- @Test(expected = RestfulObjectsApplicationException.class)
- public void whenArray() throws Exception {
- DomainResourceHelper.readAsMap("[]");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/bb79d33e/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/JsonValueEncoderTest_asAdapter.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/JsonValueEncoderTest_asAdapter.java b/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/JsonValueEncoderTest_asAdapter.java
deleted file mode 100644
index 042b1a1..0000000
--- a/component/viewer/restfulobjects/impl/src/test/java/org/apache/isis/viewer/restfulobjects/viewer/resources/domainobjects/JsonValueEncoderTest_asAdapter.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * 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.isis.viewer.restfulobjects.viewer.resources.domainobjects;
-
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-import org.codehaus.jackson.node.BigIntegerNode;
-import org.codehaus.jackson.node.BooleanNode;
-import org.codehaus.jackson.node.DecimalNode;
-import org.codehaus.jackson.node.DoubleNode;
-import org.codehaus.jackson.node.IntNode;
-import org.codehaus.jackson.node.LongNode;
-import org.codehaus.jackson.node.TextNode;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JMock;
-import org.jmock.integration.junit4.JUnit4Mockery;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
-import org.apache.isis.core.metamodel.facetapi.Facet;
-import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
-import org.apache.isis.core.metamodel.spec.ObjectSpecification;
-import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation;
-import org.apache.isis.viewer.restfulobjects.viewer.resources.domainobjects.JsonValueEncoder;
-
-@RunWith(JMock.class)
-public class JsonValueEncoderTest_asAdapter {
-
- private final Mockery context = new JUnit4Mockery();
-
- private JsonValueEncoder jsonValueEncoder;
- private JsonRepresentation representation;
- private ObjectSpecification objectSpec;
-
- private EncodableFacet encodableFacet;
- private ObjectAdapter objectAdapter;
-
- @Before
- public void setUp() throws Exception {
- objectSpec = context.mock(ObjectSpecification.class);
- encodableFacet = context.mock(EncodableFacet.class);
- objectAdapter = context.mock(ObjectAdapter.class);
-
- representation = new JsonRepresentation(TextNode.valueOf("aString"));
- jsonValueEncoder = new JsonValueEncoder();
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenSpecIsNull() throws Exception {
- jsonValueEncoder.asAdapter(null, representation);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenReprIsNull() throws Exception {
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- jsonValueEncoder.asAdapter(objectSpec, null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenReprIsAnArray() throws Exception {
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- jsonValueEncoder.asAdapter(objectSpec, JsonRepresentation.newArray());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenReprIsAMap() throws Exception {
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- assertNull(jsonValueEncoder.asAdapter(objectSpec, JsonRepresentation.newMap()));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenSpecDoesNotHaveAnEncodableFacet() throws Exception {
- allowingObjectSpecHas(EncodableFacet.class, null);
-
- assertNull(jsonValueEncoder.asAdapter(objectSpec, representation));
- }
-
- @Test
- public void whenReprIsBooleanPrimitive() throws Exception {
- whenReprIsBoolean(boolean.class);
- }
-
- @Test
- public void whenReprIsBooleanWrapper() throws Exception {
- whenReprIsBoolean(Boolean.class);
- }
-
- private void whenReprIsBoolean(final Class<?> correspondingClass) {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(correspondingClass);
- final boolean value = true;
- representation = new JsonRepresentation(BooleanNode.valueOf(value));
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenObjectSpecIsBooleanButReprIsNot() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(boolean.class);
-
- // when
- jsonValueEncoder.asAdapter(objectSpec, representation);
- }
-
- @Test
- public void whenReprIsIntegerPrimitive() throws Exception {
- whenReprIsInteger(int.class);
- }
-
- @Test
- public void whenReprIsIntegerWrapper() throws Exception {
- whenReprIsInteger(Integer.class);
- }
-
- private void whenReprIsInteger(final Class<?> correspondingClass) {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(correspondingClass);
- final int value = 123;
- representation = new JsonRepresentation(IntNode.valueOf(value));
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenObjectSpecIsIntegerButReprIsNot() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(int.class);
-
- representation = JsonRepresentation.newMap("foo", "bar");
-
- // when
- jsonValueEncoder.asAdapter(objectSpec, representation);
- }
-
- @Test
- public void whenReprIsLongPrimitive() throws Exception {
- whenReprIsLong(long.class);
- }
-
- @Test
- public void whenReprIsLongWrapper() throws Exception {
- whenReprIsLong(Long.class);
- }
-
- private void whenReprIsLong(final Class<?> correspondingClass) {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(correspondingClass);
- final long value = 1234567890L;
- representation = new JsonRepresentation(LongNode.valueOf(value));
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenObjectSpecIsLongButReprIsNot() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(long.class);
-
- // when
- jsonValueEncoder.asAdapter(objectSpec, representation);
- }
-
- @Test
- public void whenReprIsDoublePrimitive() throws Exception {
- whenReprIsDouble(double.class);
- }
-
- @Test
- public void whenReprIsDoubleWrapper() throws Exception {
- whenReprIsDouble(Double.class);
- }
-
- private void whenReprIsDouble(final Class<?> correspondingClass) {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(correspondingClass);
- final double value = 123.45;
- representation = new JsonRepresentation(DoubleNode.valueOf(value));
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenObjectSpecIsDoubleButReprIsNot() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(double.class);
-
- representation = JsonRepresentation.newMap("foo", "bar");
-
- // when
- jsonValueEncoder.asAdapter(objectSpec, representation);
- }
-
- @Test
- public void whenReprIsBigInteger() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(BigInteger.class);
- final BigInteger value = BigInteger.valueOf(123);
- representation = new JsonRepresentation(BigIntegerNode.valueOf(value));
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenObjectSpecIsBigIntegerButReprIsNot() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(BigInteger.class);
-
- representation = JsonRepresentation.newMap("foo", "bar");
-
- // when
- jsonValueEncoder.asAdapter(objectSpec, representation);
- }
-
- @Test
- public void whenReprIsBigDecimal() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(BigDecimal.class);
- final BigDecimal value = new BigDecimal("123234234.45612312343535");
- representation = new JsonRepresentation(DecimalNode.valueOf(value));
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("" + value);
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void whenObjectSpecIsBigDecimalButReprIsNot() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(BigDecimal.class);
-
- representation = JsonRepresentation.newMap("foo", "bar");
-
- // when
- jsonValueEncoder.asAdapter(objectSpec, representation);
- }
-
- @Test
- public void whenReprIsString() throws Exception {
- // given
- allowingObjectSpecHas(EncodableFacet.class, encodableFacet);
- allowingObjectSpecCorrespondingClassIs(String.class);
- representation = new JsonRepresentation(TextNode.valueOf("aString"));
-
- context.checking(new Expectations() {
- {
- one(encodableFacet).fromEncodedString("aString");
- will(returnValue(objectAdapter));
- }
- });
-
- // when
- final ObjectAdapter adapter = jsonValueEncoder.asAdapter(objectSpec, representation);
-
- // then
- assertSame(objectAdapter, adapter);
- }
-
- private <T extends Facet> void allowingObjectSpecHas(final Class<T> facetClass, final T encodableFacet) {
- context.checking(new Expectations() {
- {
- allowing(objectSpec).getFacet(facetClass);
- will(returnValue(encodableFacet));
- }
- });
- }
-
- private void allowingObjectSpecCorrespondingClassIs(final Class<?> result) {
- context.checking(new Expectations() {
- {
- allowing(objectSpec).getCorrespondingClass();
- will(returnValue(result));
- }
- });
- }
-
-}