1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.enhanced.dynamodb.document; 17 18 import java.util.Arrays; 19 import java.util.LinkedHashMap; 20 import java.util.List; 21 import java.util.Map; 22 import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider; 23 import software.amazon.awssdk.enhanced.dynamodb.EnhancedType; 24 import software.amazon.awssdk.services.dynamodb.model.AttributeValue; 25 26 public class TestData { 27 private EnhancedDocument enhancedDocument; 28 private String scenario; 29 private Map<String, AttributeValue> ddbItemMap; 30 private TypeMap typeMap; 31 private AttributeConverterProvider attributeConverterProvider; 32 getScenario()33 public String getScenario() { 34 return scenario; 35 } 36 37 private String json; 38 private boolean isGeneric; 39 dataBuilder()40 public static Builder dataBuilder(){ 41 return new Builder(); 42 } 43 isGeneric()44 public boolean isGeneric() { 45 return isGeneric; 46 } 47 getEnhancedDocument()48 public EnhancedDocument getEnhancedDocument() { 49 return enhancedDocument; 50 } 51 getDdbItemMap()52 public Map<String, AttributeValue> getDdbItemMap() { 53 return ddbItemMap; 54 } 55 getTypeMap()56 public TypeMap getTypeMap() { 57 return typeMap; 58 } 59 getAttributeConverterProvider()60 public AttributeConverterProvider getAttributeConverterProvider() { 61 return attributeConverterProvider; 62 } 63 getJson()64 public String getJson() { 65 return json; 66 } 67 TestData(Builder builder)68 public TestData(Builder builder) { 69 this.enhancedDocument = builder.enhancedDocument; 70 this.ddbItemMap = builder.ddbItemMap; 71 this.typeMap = builder.typeMap; 72 this.attributeConverterProvider = builder.attributeConverterProvider; 73 this.json = builder.json; 74 this.isGeneric = builder.isGeneric; 75 this.scenario = builder.scenario; 76 } 77 78 public static class Builder{ 79 80 private String scenario; 81 Builder()82 private Builder() { 83 } 84 85 private EnhancedDocument enhancedDocument; 86 private boolean isGeneric = true; 87 private Map<String, AttributeValue> ddbItemMap; 88 private TypeMap typeMap = new TypeMap(); 89 private AttributeConverterProvider attributeConverterProvider; 90 91 private String json; 92 enhancedDocument(EnhancedDocument enhancedDocument)93 public Builder enhancedDocument(EnhancedDocument enhancedDocument) { 94 this.enhancedDocument = enhancedDocument; 95 return this; 96 } 97 ddbItemMap(Map<String, AttributeValue> ddbItemMap)98 public Builder ddbItemMap(Map<String, AttributeValue> ddbItemMap) { 99 this.ddbItemMap = ddbItemMap; 100 return this; 101 } 102 typeMap(TypeMap typeMap)103 public Builder typeMap(TypeMap typeMap) { 104 this.typeMap = typeMap; 105 return this; 106 } 107 attributeConverterProvider(AttributeConverterProvider attributeConverterProvider)108 public Builder attributeConverterProvider(AttributeConverterProvider attributeConverterProvider) { 109 this.attributeConverterProvider = attributeConverterProvider; 110 return this; 111 } 112 isGeneric(boolean isGeneric)113 public Builder isGeneric(boolean isGeneric) { 114 this.isGeneric = isGeneric; 115 return this; 116 } 117 scenario(String scenario)118 public Builder scenario(String scenario) { 119 this.scenario = scenario; 120 return this; 121 } 122 json(String json)123 public Builder json(String json) { 124 this.json = json; 125 return this; 126 } 127 build()128 public TestData build(){ 129 return new TestData(this); 130 } 131 132 } 133 134 public static class TypeMap { TypeMap()135 private TypeMap() { 136 } 137 typeMap()138 public static TypeMap typeMap(){ 139 return new TypeMap(); 140 } 141 142 Map<String, List<EnhancedType>> enhancedTypeMap = new LinkedHashMap<>(); 143 getEnhancedTypeMap()144 public Map<String, List<EnhancedType>> getEnhancedTypeMap() { 145 return enhancedTypeMap; 146 } 147 addAttribute(String attribute, EnhancedType... enhancedType)148 public TypeMap addAttribute(String attribute, EnhancedType... enhancedType) { 149 enhancedTypeMap.put(attribute, Arrays.asList(enhancedType)); 150 return this; 151 } 152 } 153 } 154