/** @check Exceptions need to be handled */ @Test public void httpClientBadLength() throws Exception { HTTPClientTransport transport = getTransport(); URL serviceURL = serverUri.toURL(); MessageContext ctx = TestUtils.createClientMessageContextForHttpGet( TestUtils.createTestMessage(), serviceURL, 5, "local"); TransportOptions options = new TransportOptions(); boolean gotException = false; try { transport.invoke(ctx.getRequestMessage(), options); } catch (ServiceException e) { gotException = true; Assert.assertEquals(e.getMessage().substring(0, 19), "REST URL has length"); } Assert.assertTrue(gotException); }
public static String testUpdateAssetAttributes_invalidAsset() { UpdateAssetAttributesConsumer updateAssetAttributesConsumer = new UpdateAssetAttributesConsumer(); int updatedAttributesCount = 3; Properties props = CommonUtil.loadPropertyFile("properties/common.properties"); Library library = new Library(); String libraryId = props.getProperty("libraryId"); String libraryName = props.getProperty("libraryName", "GovernedAssets"); library.setLibraryId(libraryId); library.setLibraryName(libraryName); AssetKey assetKey = new AssetKey(); assetKey.setAssetId(RepositoryServiceClientConstants.INVALID_ASSET_ID); assetKey.setAssetName(RepositoryServiceClientConstants.INVALID_ASSET_NAME); assetKey.setLibrary(library); List<AttributeNameValue> attributeNameValues = new ArrayList<AttributeNameValue>(); AttributeNameValue attributeNameValue = new AttributeNameValue(); attributeNameValue.setAttributeName(RepositoryServiceClientConstants.ATTRIBUTE1_NAME); attributeNameValue.setAttributeValueString(RepositoryServiceClientConstants.ATTRIBUTE1_VALUE); attributeNameValues.add(attributeNameValue); ExtendedAssetInfo extendedAssetInfo = new ExtendedAssetInfo(); extendedAssetInfo.getAttribute().addAll(attributeNameValues); UpdateAssetAttributesRequest updateAssetAttributesRequest = new UpdateAssetAttributesRequest(); updateAssetAttributesRequest.setAssetKey(assetKey); updateAssetAttributesRequest.setExtendedAssetInfo(extendedAssetInfo); updateAssetAttributesRequest.setPartialUpdate(true); updateAssetAttributesRequest.setReplaceCurrent(true); try { UpdateAssetAttributesResponse updateAssetAttributesResponse = updateAssetAttributesConsumer .getProxy() .updateAssetAttributes(updateAssetAttributesRequest); if (updateAssetAttributesResponse == null) { throw new ServiceException(null, "Response object can not be null", null); } if (validateUpdateAssetAttributesResponse(updateAssetAttributesResponse, "negativeCase", 0) .equalsIgnoreCase("success")) { List<CommonErrorData> errorDatas = updateAssetAttributesResponse.getErrorMessage().getError(); System.out.println("The following list of errors occured"); for (CommonErrorData errorData : errorDatas) { System.out.println( "Error id: " + errorData.getErrorId() + " Error message: " + errorData.getMessage()); } return "PASSED"; } else { return "FAILED"; } } catch (ServiceException se) { se.getMessage(); se.printStackTrace(); return "FAILED"; } catch (Exception e) { e.printStackTrace(); return "FAILED"; } }
public static String testUpdateAssetAttributes_validAsset(AssetInfo assetInfo) { UpdateAssetAttributesConsumer updateAssetAttributesConsumer = new UpdateAssetAttributesConsumer(); int updatedAttributesCount = 3; AssetKey assetKey = new AssetKey(); assetKey.setAssetId(assetInfo.getBasicAssetInfo().getAssetKey().getAssetId()); assetKey.setAssetName(assetInfo.getBasicAssetInfo().getAssetKey().getAssetName()); Library library = new Library(); library.setLibraryId(assetInfo.getBasicAssetInfo().getAssetKey().getLibrary().getLibraryId()); library.setLibraryName( assetInfo.getBasicAssetInfo().getAssetKey().getLibrary().getLibraryName()); assetKey.setLibrary(library); List<AttributeNameValue> attributeNameValues = new ArrayList<AttributeNameValue>(); AttributeNameValue attributeNameValue = new AttributeNameValue(); attributeNameValue.setAttributeName(RepositoryServiceClientConstants.ATTRIBUTE1_NAME); attributeNameValue.setAttributeValueString(RepositoryServiceClientConstants.ATTRIBUTE1_VALUE); attributeNameValues.add(attributeNameValue); attributeNameValue = new AttributeNameValue(); attributeNameValue.setAttributeName(RepositoryServiceClientConstants.ATTRIBUTE2_NAME); attributeNameValue.setAttributeValueLong(RepositoryServiceClientConstants.ATTRIBUTE2_VALUE); attributeNameValues.add(attributeNameValue); attributeNameValue = new AttributeNameValue(); attributeNameValue.setAttributeName(RepositoryServiceClientConstants.ATTRIBUTE3_NAME); attributeNameValue.setAttributeValueBoolean(RepositoryServiceClientConstants.ATTRIBUTE3_VALUE); attributeNameValues.add(attributeNameValue); ExtendedAssetInfo extendedAssetInfo = new ExtendedAssetInfo(); extendedAssetInfo.getAttribute().addAll(attributeNameValues); UpdateAssetAttributesRequest updateAssetAttributesRequest = new UpdateAssetAttributesRequest(); updateAssetAttributesRequest.setAssetKey(assetKey); updateAssetAttributesRequest.setExtendedAssetInfo(extendedAssetInfo); updateAssetAttributesRequest.setPartialUpdate(true); updateAssetAttributesRequest.setReplaceCurrent(true); try { UpdateAssetAttributesResponse updateAssetAttributesResponse = updateAssetAttributesConsumer .getProxy() .updateAssetAttributes(updateAssetAttributesRequest); if (updateAssetAttributesResponse == null) { throw new ServiceException(null, "Response object can not be null", null); } if (validateUpdateAssetAttributesResponse( updateAssetAttributesResponse, "positiveCase", updatedAttributesCount) .equalsIgnoreCase("success")) { return "PASSED"; } else { return "FAILED"; } } catch (ServiceException se) { se.getMessage(); se.printStackTrace(); return "FAILED"; } catch (Exception e) { e.printStackTrace(); return "FAILED"; } }