package org.opendaylight.yangtools.yang.common;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
assertNotNull( "getErrors returned null", result.getErrors() );
assertEquals( "getErrors size", 0, result.getErrors().size() );
- result = RpcResultBuilder.<String>success( "bar" ).build();
+ result = RpcResultBuilder.success( "bar" ).build();
verifyRpcResult( result, true, "bar" );
}
.withWarning( ErrorType.RPC, "in-use", "message", "my-app-tag", "my-info", cause )
.build();
- RpcResult<String> copy = RpcResultBuilder.<String>from( result )
+ RpcResult<String> copy = RpcResultBuilder.from( result )
.withError( ErrorType.PROTOCOL, "error message" )
.build();
verifyRpcResult( copy, true, "foo" );
"error message", null, null, null );
}
+ @Test
+ public void testErrors() {
+ final RpcResultBuilder<Object> rpcResultBuilder = RpcResultBuilder.status(true);
+ final RpcError rpcErrorShort = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg");
+ final RpcError rpcErrorLong = RpcResultBuilder.newError(RpcError.ErrorType.RPC, "tag", "msg", "applicationTag",
+ "info", null);
+ final RpcError rpcErrorShortWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg");
+ final RpcError rpcErrorLongWarn = RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "tag", "msg",
+ "applicationTag",
+ "info", null);
+ rpcResultBuilder.withRpcError(rpcErrorShort);
+ final RpcResult<Object> rpcResult = rpcResultBuilder.build();
+ final RpcResultBuilder<RpcResult<Object>> rpcResultRpcResultBuilder1 = RpcResultBuilder.success
+ (rpcResultBuilder);
+ final RpcResultBuilder<RpcResult<Object>> rpcResultRpcResultBuilder2 = rpcResultRpcResultBuilder1.withResult
+ (rpcResultBuilder);
+
+ assertEquals(rpcErrorShort.getErrorType(), rpcErrorShortWarn.getErrorType());
+ assertEquals(rpcErrorLong.getErrorType(), rpcErrorLongWarn.getErrorType());
+ assertEquals(rpcResultRpcResultBuilder1, rpcResultRpcResultBuilder2);
+ assertNotNull(rpcResultBuilder.buildFuture());
+ assertEquals("RpcResult [successful=true, result=null, errors=[RpcError [message=msg, severity=ERROR, " +
+ "errorType=RPC, tag=tag, applicationTag=null, info=null, cause=null]]]", rpcResult.toString());
+ }
+
@SuppressWarnings("unchecked")
@Test
public void testSerialization() throws Exception {
"error message", "my-app-tag", "my-info", cause );
}
- void verifyRpcError( RpcResult<?> result, int errorIndex, ErrorSeverity expSeverity,
- ErrorType expErrorType, String expTag, String expMessage, String expAppTag,
- String expInfo, Throwable expCause ) {
+ void verifyRpcError( final RpcResult<?> result, final int errorIndex, final ErrorSeverity expSeverity,
+ final ErrorType expErrorType, final String expTag, final String expMessage, final String expAppTag,
+ final String expInfo, final Throwable expCause ) {
List<RpcError> errors = new ArrayList<>( result.getErrors() );
assertTrue( "Expected error at index " + errorIndex + " not found",
assertEquals( "getCause", expCause, error.getCause() );
}
- void verifyRpcResult( RpcResult<?> result, boolean expSuccess, Object expValue ) {
+ void verifyRpcResult( final RpcResult<?> result, final boolean expSuccess, final Object expValue ) {
assertEquals( "isSuccessful", expSuccess, result.isSuccessful() );
assertEquals( "getResult", expValue, result.getResult() );
}
-}
+}
\ No newline at end of file