Java tutorial
/* * ****************************************************************************** * Copyright 2014-2015 Spectra Logic Corporation. 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. A copy of the License is located at * * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. * This file 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 com.spectralogic.ds3autogen.test.helpers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.spectralogic.ds3autogen.api.models.apispec.*; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** * This class provides utilities for testing the Remove Dollar Sign Converter utility */ public final class RemoveDollarSignConverterHelper { private RemoveDollarSignConverterHelper() { } /** * Creates a populated list of Ds3AnnotationElements */ public static ImmutableList<Ds3AnnotationElement> createPopulatedAnnotationElements() { return ImmutableList.of(new Ds3AnnotationElement("CollectionValue", "Pools", "java.lang.String"), new Ds3AnnotationElement("CollectionValueRenderingMode", "SINGLE_BLOCK_FOR_ALL_ELEMENTS", "com.spectralogic.util.marshal.CustomMarshaledName$CollectionNameRenderingMode")); } /** * Creates a populated list of Ds3Annotations */ public static ImmutableList<Ds3Annotation> createPopulatedAnnotations() { return ImmutableList.of(new Ds3Annotation("com.spectralogic.util.bean.lang.SortBy$Direction", null), new Ds3Annotation("com.spectralogic.util.bean.lang.Optional", createPopulatedAnnotationElements())); } /** * Creates a populated list of Ds3Elements */ public static ImmutableList<Ds3Element> createPopulatedElements() { return ImmutableList.of( new Ds3Element("Name", "com.test.package.One$Two", "com.test.package.Three$Four", false), new Ds3Element("Name", "com.test.package.Five$Six", "com.test.package.Seven$Eight", createPopulatedAnnotations(), false)); } /** * Creates a populated list of Ds3Elements. The associated types in this * list do not contain any '$' symbols */ public static ImmutableList<Ds3Element> createElementsForMap(final String variation) { return ImmutableList.of(new Ds3Element("ElementOne" + variation, "Type", "ComponentType", false), new Ds3Element("ElementTwo" + variation, "Type", "ComponentType", false)); } /** * Creates a populated list of Ds3EnumConstants. The associated types in this * list do not contain any '$' symbols */ public static ImmutableList<Ds3EnumConstant> createEnumConstantsForMap(final String variation) { return ImmutableList.of(new Ds3EnumConstant("EnumOne" + variation, null), new Ds3EnumConstant("EnumTwo" + variation, null)); } /** * Creates a populated list of Ds3Params */ public static ImmutableList<Ds3Param> createPopulatedParams(final String variation) { return ImmutableList.of( new Ds3Param("Name" + variation, "com.test.package.Base$TypeOne" + variation, false), new Ds3Param("Name" + variation, "com.test.package.Base$TypeTwo" + variation, false)); } /** * Checks if a list of Ds3Params generated by the createPopulatedParams function * has successfully changed all type names to remove the '$' symbol. Assumes * that the specified variation matches the variation used during the param * list generation. */ public static void checkAutoPopulatedParams(final ImmutableList<Ds3Param> params, final String variation) { assertThat(params.size(), is(2)); assertThat(params.get(0).getType(), is("com.test.package.TypeOne" + variation)); assertThat(params.get(1).getType(), is("com.test.package.TypeTwo" + variation)); } /** * Creates a populated list of Ds3ResponseTypes */ public static ImmutableList<Ds3ResponseType> createPopulatedResponseTypes() { return ImmutableList.of(new Ds3ResponseType("com.test.package.Base$Type1", "com.test.package.Base$Type2"), new Ds3ResponseType("com.test.package.Base$Type3", "com.test.package.Base$Type4")); } /** * Creates a populated list of Ds3ResponseCodes */ public static ImmutableList<Ds3ResponseCode> createPopulatedResponseCodes() { return ImmutableList.of(new Ds3ResponseCode(200, createPopulatedResponseTypes()), new Ds3ResponseCode(204, createPopulatedResponseTypes())); } /** * Checks if a list of Ds3Response codes generated by the createPopulatedResponseCodes * function has successfully changed all type names by removing the '$' symbol */ public static void checkAutoPopulatedResponseCodes(final ImmutableList<Ds3ResponseCode> responseCodes) { assertThat(responseCodes.size(), is(2)); final ImmutableList<Ds3ResponseType> firstResponseTypes = responseCodes.get(0).getDs3ResponseTypes(); assertThat(firstResponseTypes.size(), is(2)); assertThat(firstResponseTypes.get(0).getType(), is("com.test.package.Type1")); assertThat(firstResponseTypes.get(0).getComponentType(), is("com.test.package.Type2")); assertThat(firstResponseTypes.get(1).getType(), is("com.test.package.Type3")); assertThat(firstResponseTypes.get(1).getComponentType(), is("com.test.package.Type4")); final ImmutableList<Ds3ResponseType> secondResponseTypes = responseCodes.get(1).getDs3ResponseTypes(); assertThat(secondResponseTypes.size(), is(2)); assertThat(secondResponseTypes.get(0).getType(), is("com.test.package.Type1")); assertThat(secondResponseTypes.get(0).getComponentType(), is("com.test.package.Type2")); assertThat(secondResponseTypes.get(1).getType(), is("com.test.package.Type3")); assertThat(secondResponseTypes.get(1).getComponentType(), is("com.test.package.Type4")); } /** * Creates a populated Ds3Request with names containing '$' symbol. The type names * vary based on the variation parameter */ public static Ds3Request createPopulatedRequest(final String variation) { return new Ds3Request("com.test.package.Base$RequestType" + variation, null, null, null, null, null, null, null, null, false, createPopulatedResponseCodes(), createPopulatedParams(variation), createPopulatedParams(variation)); } /** * Checks if a Ds3Request generated by the createPopulatedRequest function has * successfully changed all type names to remove the '$' symbol. Assumes that * the specified variation matches the variation used during request generation */ public static void checkAutoPopulatedRequest(final Ds3Request request, final String variation) { checkAutoPopulatedResponseCodes(request.getDs3ResponseCodes()); checkAutoPopulatedParams(request.getOptionalQueryParams(), variation); checkAutoPopulatedParams(request.getRequiredQueryParams(), variation); } /** * Creates a populated Ds3Type map with names containing '$' symbol */ public static ImmutableMap<String, Ds3Type> createPopulatedMap() { final Ds3Type type1 = createPopulatedType("_v1"); final Ds3Type type2 = createPopulatedType("_v2"); return ImmutableMap.of(type1.getName(), type1, type2.getName(), type2); } /** * Checks if a Type Map generated by the createPopulatedMap function has * successfully changed all type names by removing the '$' symbol */ public static void checkAutoPopulatedMap(final ImmutableMap<String, Ds3Type> map) { assertThat(map.size(), is(2)); assertTrue(map.containsKey("com.test.package.Ds3Type_v1")); assertTrue(map.containsKey("com.test.package.Ds3Type_v2")); checkAutoPopulatedType(map.get("com.test.package.Ds3Type_v1"), "_v1"); checkAutoPopulatedType(map.get("com.test.package.Ds3Type_v2"), "_v2"); } /** * Creates a populated Ds3Type with names containing '$' symbol. The type * names vary based on the variation parameter */ public static Ds3Type createPopulatedType(final String variation) { return new Ds3Type("com.test.package.Base$Ds3Type" + variation, createPopulatedElements()); } /** * Checks if a Ds3Type generated by the createPopulatedType function has * successfully changed all type names by removing the '$' symbol. Assumes that * the specified variation matches the variation used during type generation */ public static void checkAutoPopulatedType(final Ds3Type type, final String variation) { assertThat(type.getName(), is("com.test.package.Ds3Type" + variation)); assertThat(type.getElements().size(), is(2)); assertThat(type.getElements().get(0).getType(), is("com.test.package.Two")); assertThat(type.getElements().get(0).getComponentType(), is("com.test.package.Four")); } }