/******************************************************************************* * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved. * Licensed 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 *******************************************************************************/ package org.ebayopensource.turmeric.runtime.tests.common.sif.invalidconfig; import java.net.URL; import java.util.concurrent.ExecutionException; import org.ebayopensource.turmeric.runtime.binding.BindingConstants; import org.ebayopensource.turmeric.runtime.common.exceptions.ServiceInvocationExceptionInterface; import org.ebayopensource.turmeric.runtime.common.types.SOAConstants; import org.junit.Assert; import org.ebayopensource.turmeric.runtime.errorlibrary.ErrorDataCollection; import org.ebayopensource.turmeric.runtime.sif.service.Service; import org.ebayopensource.turmeric.runtime.tests.common.sif.Test1Driver; import org.ebayopensource.turmeric.common.v1.types.ErrorMessage; public class Test1DriverExt extends Test1Driver { public Test1DriverExt(String serviceName, String clientName, String configRoot, URL serviceURL, String reqDataFormat, String resDataFormat) { super(serviceName, clientName, configRoot, serviceURL, reqDataFormat, resDataFormat); } public Test1DriverExt(String serviceName, String clientName, String configRoot, URL serviceURL) { this(serviceName, clientName, configRoot, serviceURL, null, null); } @Override protected void checkError(Service service, Object e, boolean isProxy, TestMode mode, boolean isResponseGet) throws Exception { if (!(service.getInvokerOptions().getResponseBinding().equalsIgnoreCase(BindingConstants.PAYLOAD_JSON) || service.getInvokerOptions().getResponseBinding().equalsIgnoreCase(BindingConstants.PAYLOAD_NV) )) { // Default to Super's error processing when the response format is // not JSON nor NV super.checkError(service, e, isProxy, mode, isResponseGet); } else { if (e instanceof ExecutionException) e = ((ExecutionException) e).getCause(); if (e instanceof ServiceInvocationExceptionInterface) { ServiceInvocationExceptionInterface sie = (ServiceInvocationExceptionInterface) e; Object response = sie.getErrorResponse(); if (response != null && sie.isAppOnlyException()) { e = response; } } /* * The fallback service desc assumes a single namespace() configuration.. so no prefixes. * The current client side configuration for the testcase is a multiNS, so it expects prefixes. * * The JSON format fails as the ObjectNodeStreamImpl node doesn't have prefix and thus doesn't match * expected errorRootNode. * * For NV, the server does not stream the root node, the root node is added by the client framework with the CTNS namespace. * This matches the expected errorRootNode, but the sub-elements are not deserialized as the prefixes are missing. * The ErrorMessage doesn't have errorData. The below checks are done accordingly. */ if (service.getInvokerOptions().getResponseBinding().equalsIgnoreCase(BindingConstants.PAYLOAD_NV)) { Assert.assertTrue("Expecting errorMessage root element", (e instanceof ErrorMessage)); } else { Assert.assertTrue("Expecting errorMessage root element", e.toString().equalsIgnoreCase(SOAConstants.ERROR_MESSAGE_ELEMENT_NAME.getLocalPart())); } } } @Override public boolean unexpectedError(long errorId, long expectedErrorId) { // Copied from Test1Driver.unexpectedError() into here to limit this // odd behavior to just this specific test case. // HACK: This combo of values indicates no error, let it pass. long hackErrorId = ErrorDataCollection.svc_factory_cannot_create_svc.getErrorId(); long hackExpectedId = ErrorDataCollection.svc_factory_service_init_failed.getErrorId(); if ((errorId == hackErrorId) && (expectedErrorId == hackExpectedId)) { return false; } System.out.printf("errorId [%d]%n", errorId); System.out.printf("expectedErrorId [%d]%n", errorId ); return super.unexpectedError(errorId, expectedErrorId); } }