You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by mf...@apache.org on 2011/05/23 21:03:03 UTC
svn commit: r1126663 - in /incubator/rave/trunk/rave-portal/src:
main/java/org/apache/rave/portal/service/
main/java/org/apache/rave/portal/web/api/rpc/
main/java/org/apache/rave/portal/web/api/rpc/model/
test/java/org/apache/rave/portal/service/ test/...
Author: mfranklin
Date: Mon May 23 19:03:02 2011
New Revision: 1126663
URL: http://svn.apache.org/viewvc?rev=1126663&view=rev
Log:
Added RPC API infrastructure (supports RAVE-33)
Added:
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/DefaultRegionService.java
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/RegionService.java
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcOperation.java
incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcResult.java
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/RegionServiceTest.java
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcOperationTest.java
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcResultTest.java
Modified:
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/UserServiceTest.java
incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/w3c/service/impl/WookieWidgetServiceTest.java
Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/DefaultRegionService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/DefaultRegionService.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/DefaultRegionService.java (added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/DefaultRegionService.java Mon May 23 19:03:02 2011
@@ -0,0 +1,31 @@
+/*
+ * 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.rave.portal.service;
+
+import org.apache.rave.portal.model.RegionWidget;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DefaultRegionService implements RegionService {
+ @Override
+ public RegionWidget moveRegionWidget(long regionWidgetId, int newPosition, long toRegion, long fromRegion) {
+ return null;
+ }
+}
Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/RegionService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/RegionService.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/RegionService.java (added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/RegionService.java Mon May 23 19:03:02 2011
@@ -0,0 +1,26 @@
+/*
+ * 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.rave.portal.service;
+
+import org.apache.rave.portal.model.RegionWidget;
+
+public interface RegionService {
+ RegionWidget moveRegionWidget(long regionWidgetId, int newPosition, long toRegion, long fromRegion);
+}
Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java (added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java Mon May 23 19:03:02 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.rave.portal.web.api.rpc;
+
+import org.apache.rave.exception.NotSupportedException;
+import org.apache.rave.portal.model.RegionWidget;
+import org.apache.rave.portal.service.RegionService;
+import org.apache.rave.portal.web.api.rpc.model.RpcOperation;
+import org.apache.rave.portal.web.api.rpc.model.RpcResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Provides RPC functions via the API.
+ */
+@Controller
+@RequestMapping(value = "/api/rpc/page/*")
+public class PageApi {
+
+ private final RegionService regionService;
+
+ @Autowired
+ public PageApi(RegionService regionService) {
+ this.regionService = regionService;
+ }
+
+ //Generic method for RegionWidget RPC ops
+ @RequestMapping(method = RequestMethod.POST, value = "/regionWidget/{region_widget_id}")
+ public RpcResult<RegionWidget> moveRegionWidget(@PathVariable final long region_widget_id,
+ @RequestParam final RpcOperation.Type operation,
+ @RequestParam final int new_position,
+ @RequestParam final long to_region,
+ @RequestParam final long from_region) {
+ RpcResult<RegionWidget> result;
+ switch (operation) {
+ case MOVE: {
+ result = new RpcOperation<RegionWidget>() {
+ @Override
+ public RegionWidget execute() {
+ return regionService.moveRegionWidget(region_widget_id, new_position, to_region, from_region);
+ }
+ }.getResult();
+ break;
+ }
+ case DELETE:
+ result = new RpcOperation<RegionWidget>() {
+ @Override
+ public RegionWidget execute() {
+ throw new NotSupportedException("Not Supported");
+ }
+ }.getResult();
+ break;
+ default: {
+ result = new RpcResult<RegionWidget>(true, "Invalid Operation Specified: " + operation, RpcResult.ErrorCode.INVALID_PARAMS);
+ }
+ }
+
+ return result;
+ }
+}
Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcOperation.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcOperation.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcOperation.java (added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcOperation.java Mon May 23 19:03:02 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rave.portal.web.api.rpc.model;
+
+import org.apache.rave.portal.model.RegionWidget;
+
+/**
+ * Defines an RPC operation that can be executed to return a given result
+ */
+public abstract class RpcOperation<T> {
+ public static enum Type {
+ MOVE,
+ DELETE
+ }
+
+ /**
+ *
+ * @return
+ */
+ public RpcResult<T> getResult(){
+ RpcResult<T> result;
+ try {
+ T subject = execute();
+ result = new RpcResult<T>(false, subject);
+ } catch (IllegalArgumentException e) {
+ result = new RpcResult<T>(true, e.getMessage(), RpcResult.ErrorCode.INVALID_PARAMS);
+ } catch (Exception e) {
+ result = new RpcResult<T>(true, e.getMessage(), RpcResult.ErrorCode.INTERNAL_ERROR);
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public abstract T execute();
+}
Added: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcResult.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcResult.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcResult.java (added)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/model/RpcResult.java Mon May 23 19:03:02 2011
@@ -0,0 +1,98 @@
+/*
+ * 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.rave.portal.web.api.rpc.model;
+
+/**
+ * Result context for RPC operations for a given type
+ */
+public class RpcResult<T> {
+
+ public static enum ErrorCode {
+ NO_ERROR,
+ INVALID_PARAMS,
+ INTERNAL_ERROR
+ }
+
+ private boolean error;
+ private String errorMessage;
+ private ErrorCode errorCode;
+ private T result;
+
+ public RpcResult(boolean error) {
+ this.error = error;
+ setDefaultCode(error);
+ }
+
+ public RpcResult(boolean error, T result) {
+ this.error = error;
+ this.result = result;
+ setDefaultCode(error);
+ }
+
+ public RpcResult(boolean error, String errorMessage, ErrorCode errorCode) {
+ this.error = error;
+ this.errorMessage = errorMessage;
+ this.errorCode = errorCode;
+ }
+
+ public RpcResult(boolean error, String errorMessage, ErrorCode errorCode, T result) {
+ this.error = error;
+ this.errorMessage = errorMessage;
+ this.errorCode = errorCode;
+ this.result = result;
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
+ public void setError(boolean error) {
+ this.error = error;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ public ErrorCode getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(ErrorCode errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public T getResult() {
+ return result;
+ }
+
+ public void setResult(T result) {
+ this.result = result;
+ }
+
+ private void setDefaultCode(boolean error) {
+ errorCode = error ? ErrorCode.INTERNAL_ERROR : ErrorCode.NO_ERROR;
+ }
+
+}
Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/RegionServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/RegionServiceTest.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/RegionServiceTest.java (added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/RegionServiceTest.java Mon May 23 19:03:02 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.rave.portal.service;
+
+
+import org.junit.Before;
+
+public class RegionServiceTest {
+
+ private RegionService regionService;
+
+ @Before
+ public void setup() {
+ regionService = new DefaultRegionService();
+ }
+
+}
Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/UserServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/UserServiceTest.java?rev=1126663&r1=1126662&r2=1126663&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/UserServiceTest.java (original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/UserServiceTest.java Mon May 23 19:03:02 2011
@@ -38,11 +38,6 @@ import static org.hamcrest.CoreMatchers.
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
-/**
- * @author mfranklin
- * Date: 4/25/11
- * Time: 4:16 PM
- */
public class UserServiceTest {
private static final Long USER_ID = 1234L;
Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java (added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java Mon May 23 19:03:02 2011
@@ -0,0 +1,101 @@
+/*
+ * 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.rave.portal.web.api.rpc;
+
+import org.apache.rave.portal.model.RegionWidget;
+import org.apache.rave.portal.service.RegionService;
+import org.apache.rave.portal.web.api.rpc.model.RpcOperation;
+import org.apache.rave.portal.web.api.rpc.model.RpcResult;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.assertThat;
+
+/** */
+public class PageApiTest {
+
+ private static final String PARAM_ERROR_MESSAGE = "Target Region does not exist";
+ private static final String INTERNAL_ERROR_MESSAGE = "Internal Error";
+ private static final RpcOperation.Type MOVE = RpcOperation.Type.MOVE;
+ private PageApi pageApi;
+ private RegionService regionService;
+ private static final long REGION_WIDGET_ID = 35;
+ private static final int NEW_POSITION = 3;
+
+
+ @Before
+ public void setup() {
+ regionService = createNiceMock(RegionService.class);
+ pageApi = new PageApi(regionService);
+ }
+
+ @Test
+ public void moveWidget_validParams() {
+ final RpcOperation.Type OPERATION = MOVE;
+ final int TO_REGION = 1;
+ final long FROM_REGION = 2;
+
+ expect(regionService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andReturn(new RegionWidget());
+ replay(regionService);
+ RpcResult<RegionWidget> result = pageApi.moveRegionWidget(REGION_WIDGET_ID, OPERATION, NEW_POSITION, TO_REGION, FROM_REGION);
+ verify(regionService);
+ assertThat(result, is(notNullValue()));
+ assertThat(result.getResult(), is(notNullValue()));
+ assertThat(result.isError(), is(false));
+ assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.NO_ERROR));
+ assertThat(result.getErrorMessage(), is(nullValue()));
+ }
+
+ @Test
+ public void moveWidget_invalidParams() {
+ final long TO_REGION = -1;
+ final long FROM_REGION = 2;
+
+ expect(regionService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
+ replay(regionService);
+
+ RpcResult<RegionWidget> result = pageApi.moveRegionWidget(REGION_WIDGET_ID, MOVE, NEW_POSITION, TO_REGION, FROM_REGION);
+ verify(regionService);
+ assertThat(result, is(notNullValue()));
+ assertThat(result.getResult(), is(nullValue()));
+ assertThat(result.isError(), is(true));
+ assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INVALID_PARAMS));
+ assertThat(result.getErrorMessage(), is(equalTo(PARAM_ERROR_MESSAGE)));
+ }
+
+ @Test
+ public void moveWidget_internalError() {
+ final long TO_REGION = 1;
+ final long FROM_REGION = 2;
+
+ expect(regionService.moveRegionWidget(REGION_WIDGET_ID, NEW_POSITION, TO_REGION, FROM_REGION)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
+ replay(regionService);
+
+ RpcResult<RegionWidget> result = pageApi.moveRegionWidget(REGION_WIDGET_ID, MOVE, NEW_POSITION, TO_REGION, FROM_REGION);
+ verify(regionService);
+ assertThat(result, is(notNullValue()));
+ assertThat(result.getResult(), is(nullValue()));
+ assertThat(result.isError(), is(true));
+ assertThat(result.getErrorCode(), is(RpcResult.ErrorCode.INTERNAL_ERROR));
+ assertThat(result.getErrorMessage(), is(equalTo(INTERNAL_ERROR_MESSAGE)));
+ }
+}
Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcOperationTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcOperationTest.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcOperationTest.java (added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcOperationTest.java Mon May 23 19:03:02 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.rave.portal.web.api.rpc.model;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class RpcOperationTest {
+
+ private static final String BOO = "BOO";
+
+ @Test
+ public void execute_valid() {
+ RpcOperation<String> valid = new RpcOperation<String>() {
+ @Override
+ public String execute() {
+ return BOO;
+ }
+ };
+
+ RpcResult<String> result = valid.getResult();
+ assertThat(result.getResult(), is(equalTo(BOO)));
+ assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.NO_ERROR)));
+ }
+ @Test
+ public void execute_invalidArgs() {
+ RpcOperation<String> valid = new RpcOperation<String>() {
+ @Override
+ public String execute() {
+ throw new IllegalArgumentException();
+ }
+ };
+
+ RpcResult<String> result = valid.getResult();
+ assertThat(result.getResult(), is(nullValue()));
+ assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.INVALID_PARAMS)));
+ }
+ @Test
+ public void execute_internalError() {
+ RpcOperation<String> valid = new RpcOperation<String>() {
+ @Override
+ public String execute() {
+ throw new RuntimeException("Illegal Error");
+ }
+ };
+
+ RpcResult<String> result = valid.getResult();
+ assertThat(result.getResult(), is(nullValue()));
+ assertThat(result.getErrorCode(), is(equalTo(RpcResult.ErrorCode.INTERNAL_ERROR)));
+ }
+}
Added: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcResultTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcResultTest.java?rev=1126663&view=auto
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcResultTest.java (added)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/model/RpcResultTest.java Mon May 23 19:03:02 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.rave.portal.web.api.rpc.model;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class RpcResultTest {
+
+ @Test
+ public void corretDefault_noError() {
+ assertThat(new RpcResult<String>(false).getErrorCode(), is(equalTo(RpcResult.ErrorCode.NO_ERROR)));
+ }
+ @Test
+ public void corretDefault_error() {
+ assertThat(new RpcResult<String>(true).getErrorCode(), is(equalTo(RpcResult.ErrorCode.INTERNAL_ERROR)));
+ }
+}
Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/w3c/service/impl/WookieWidgetServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/w3c/service/impl/WookieWidgetServiceTest.java?rev=1126663&r1=1126662&r2=1126663&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/w3c/service/impl/WookieWidgetServiceTest.java (original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/w3c/service/impl/WookieWidgetServiceTest.java Mon May 23 19:03:02 2011
@@ -19,10 +19,6 @@
package org.apache.rave.w3c.service.impl;
-/**
- * @author mfranklin
- * Date: 5/19/11
- * Time: 1:00 PM
- */
+
public class WookieWidgetServiceTest {
}