
com.atlan.generators.AssetTestGenerator Maven / Gradle / Ivy
// Generated by delombok at Thu Oct 10 18:56:33 UTC 2024
/* SPDX-License-Identifier: Apache-2.0
Copyright 2023 Atlan Pte. Ltd. */
package com.atlan.generators;
import com.atlan.generators.lombok.Singulars;
import com.atlan.model.enums.AtlanEnum;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
public class AssetTestGenerator extends AssetGenerator {
@java.lang.SuppressWarnings("all")
@lombok.Generated
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AssetTestGenerator.class);
public static final String DIRECTORY = "assets";
private static final String ASSET_GUID = "705d96f4-bdb6-4792-8dfe-8dc4ca3d2c23";
private static final String ASSET_QN = "default/snowflake/1234567890/test/qualifiedName";
protected final AssetGenerator asset;
protected final List testAttributes;
public AssetTestGenerator(AssetGenerator asset, GeneratorConfig cfg) {
super(asset.getEntityDef(), cfg);
this.asset = asset;
this.testAttributes = new ArrayList<>();
}
@Override
public void resolveDetails() {
super.resolveDetails();
addTestAttributes(asset);
}
public static final class TestAttribute {
private SearchableAttribute> details;
private String builderMethod;
private List values;
private List rawValues;
private boolean inherited;
private boolean relationship;
private String relatedTypeOriginal;
@java.lang.SuppressWarnings("all")
@lombok.Generated
TestAttribute(final SearchableAttribute> details, final String builderMethod, final List values, final List rawValues, final boolean inherited, final boolean relationship, final String relatedTypeOriginal) {
this.details = details;
this.builderMethod = builderMethod;
this.values = values;
this.rawValues = rawValues;
this.inherited = inherited;
this.relationship = relationship;
this.relatedTypeOriginal = relatedTypeOriginal;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public static class TestAttributeBuilder {
@java.lang.SuppressWarnings("all")
@lombok.Generated
private SearchableAttribute> details;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private String builderMethod;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private List values;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private List rawValues;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private boolean inherited;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private boolean relationship;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private String relatedTypeOriginal;
@java.lang.SuppressWarnings("all")
@lombok.Generated
TestAttributeBuilder() {
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder details(final SearchableAttribute> details) {
this.details = details;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder builderMethod(final String builderMethod) {
this.builderMethod = builderMethod;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder values(final List values) {
this.values = values;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder rawValues(final List rawValues) {
this.rawValues = rawValues;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder inherited(final boolean inherited) {
this.inherited = inherited;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder relationship(final boolean relationship) {
this.relationship = relationship;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute.TestAttributeBuilder relatedTypeOriginal(final String relatedTypeOriginal) {
this.relatedTypeOriginal = relatedTypeOriginal;
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public AssetTestGenerator.TestAttribute build() {
return new AssetTestGenerator.TestAttribute(this.details, this.builderMethod, this.values, this.rawValues, this.inherited, this.relationship, this.relatedTypeOriginal);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.lang.String toString() {
return "AssetTestGenerator.TestAttribute.TestAttributeBuilder(details=" + this.details + ", builderMethod=" + this.builderMethod + ", values=" + this.values + ", rawValues=" + this.rawValues + ", inherited=" + this.inherited + ", relationship=" + this.relationship + ", relatedTypeOriginal=" + this.relatedTypeOriginal + ")";
}
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public static AssetTestGenerator.TestAttribute.TestAttributeBuilder builder() {
return new AssetTestGenerator.TestAttribute.TestAttributeBuilder();
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public SearchableAttribute> getDetails() {
return this.details;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public String getBuilderMethod() {
return this.builderMethod;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public List getValues() {
return this.values;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public List getRawValues() {
return this.rawValues;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean getInherited() {
return this.inherited;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean getRelationship() {
return this.relationship;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public String getRelatedTypeOriginal() {
return this.relatedTypeOriginal;
}
}
private void addTestAttributes(AssetGenerator assetGenerator) {
Set superTypes = assetGenerator.getSuperTypes();
if (superTypes != null && !superTypes.isEmpty()) {
for (String superType : superTypes) {
if (superType != null && !superType.equals("Referenceable")) {
// We can short-circuit when the next level up is Referenceable (the top)
addTestAttributes(cache.getCachedAssetType(superType), true);
}
}
}
// Add attributes for this class itself
addTestAttributes(assetGenerator, false);
}
private void addTestAttributes(AssetGenerator assetGenerator, boolean fromSuperType) {
Set> attributes = assetGenerator.getNonInheritedAttributes();
if (attributes != null) {
for (SearchableAttribute> attribute : attributes) {
TestAttribute.TestAttributeBuilder builder = TestAttribute.builder().details(attribute);
MappedType type = attribute.getType();
boolean multiValued = attribute.getSingular() != null;
String renamedAttr = attribute.getRenamed();
if (!renamedAttr.equals("serialVersionUID")) {
String builderMethod = renamedAttr;
if (multiValued) {
// If the attribute can be multivalued, figure out the singular form of the
// attribute's name
if (attribute.getSingular().isEmpty()) {
builderMethod = Singulars.autoSingularize(renamedAttr);
} else {
builderMethod = attribute.getSingular();
}
}
builder.builderMethod(builderMethod).inherited(fromSuperType);
switch (type.getType()) {
case PRIMITIVE:
addPrimitive(builder, multiValued, type.getName(), type.getContainer());
break;
case ENUM:
addEnum(builder, multiValued, type.getName());
break;
case ASSET:
builder.relatedTypeOriginal(type.getOriginalBase());
if (!attribute.getRetyped()) {
addAssetRef(builder, multiValued, type.getName());
} else {
// If the attribute was retyped, use the original base type for
// generating test values, or we'll end up with a non-existent
// abstract class for the test
addAssetRef(builder, multiValued, type.getOriginalBase());
}
break;
case STRUCT:
addStructRef(builder, multiValued, type.getName());
break;
default:
log.warn("Unhandled testing type {} - skipping.", type.getType());
break;
}
}
}
} else if (!assetGenerator.getOriginalName().equals("Referenceable")) {
log.warn("No attributes found for {}, skipping any test inclusion.", assetGenerator.getOriginalName());
}
}
private void addPrimitive(TestAttribute.TestAttributeBuilder builder, boolean multiValued, String typeName, String containerName) {
builder.relationship(false);
if (!multiValued) {
testAttributes.add(builder.values(List.of(getPrimitiveValue(containerName, typeName, 0))).rawValues(List.of(getRawPrimitiveValue(containerName, typeName, 0))).build());
} else {
testAttributes.add(builder.values(List.of(getPrimitiveValue(containerName, typeName, 0), getPrimitiveValue(containerName, typeName, 1))).rawValues(List.of(getRawPrimitiveValue(containerName, typeName, 0), getRawPrimitiveValue(containerName, typeName, 1))).build());
}
}
private String getPrimitiveValue(String containerName, String typeName, int count) {
String value = null;
switch (typeName) {
case "String":
value = "\"" + typeName + count + "\"";
break;
case "Boolean":
if (Math.floorMod(count, 2) == 0) {
value = "true";
} else {
value = "false";
}
break;
case "Integer":
if (Math.floorMod(count, 2) == 0) {
value = "123";
} else {
value = "456";
}
break;
case "Long":
if (Math.floorMod(count, 2) == 0) {
value = "123456789L";
} else {
value = "987654321L";
}
break;
case "Double":
if (Math.floorMod(count, 2) == 0) {
value = "123.456";
} else {
value = "654.321";
}
break;
case "String, String":
if (containerName.equals("List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy