Break dependency of metadata-test-utils on metadata-models.

This commit is contained in:
John Plaisted 2020-09-09 13:21:16 -07:00
parent f07420a434
commit 96da83033c
10 changed files with 170 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.List;
import org.testng.annotations.Test;
import static com.linkedin.metadata.testing.Urns.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static org.testng.Assert.*;

View File

@ -9,6 +9,7 @@ import java.util.Arrays;
import java.util.List;
import org.testng.annotations.Test;
import static com.linkedin.metadata.testing.Urns.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static org.testng.Assert.*;

View File

@ -62,6 +62,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static com.linkedin.metadata.dao.utils.RegisteredUrnPathExtractors.*;
import static com.linkedin.metadata.testing.AuditStamps.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static com.linkedin.testing.TestUtils.*;
import static org.mockito.Mockito.*;

View File

@ -11,6 +11,7 @@ import java.util.Optional;
import org.json.simple.parser.ParseException;
import org.testng.annotations.Test;
import static com.linkedin.metadata.testing.AuditStamps.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static com.linkedin.testing.TestUtils.*;
import static org.testng.Assert.*;

View File

@ -25,6 +25,7 @@ import org.mockito.stubbing.OngoingStubbing;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static com.linkedin.metadata.testing.AuditStamps.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static org.mockito.Mockito.*;
import static org.testng.Assert.*;

View File

@ -36,6 +36,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static com.linkedin.metadata.dao.BaseReadDAO.LATEST_VERSION;
import static com.linkedin.metadata.testing.AuditStamps.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static com.linkedin.testing.TestUtils.*;
import static org.mockito.Mockito.*;

View File

@ -27,7 +27,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static com.linkedin.metadata.dao.BaseReadDAO.*;
import static com.linkedin.metadata.utils.TestUtils.*;
import static com.linkedin.metadata.testing.AuditStamps.*;
import static com.linkedin.testing.TestUtils.*;
import static org.mockito.Mockito.*;
import static org.testng.Assert.*;

View File

@ -0,0 +1,34 @@
package com.linkedin.metadata.testing;
import com.linkedin.common.AuditStamp;
import com.linkedin.common.urn.CorpuserUrn;
import com.linkedin.common.urn.Urn;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class AuditStamps {
private AuditStamps() {
}
@Nonnull
public static AuditStamp makeAuditStamp(@Nonnull Urn actorUrn, @Nullable Urn impersonatorUrn, long time) {
AuditStamp auditStamp = new AuditStamp();
auditStamp.setTime(time);
auditStamp.setActor(actorUrn);
if (impersonatorUrn != null) {
auditStamp.setImpersonator(impersonatorUrn);
}
return auditStamp;
}
@Nonnull
public static AuditStamp makeAuditStamp(@Nonnull String actorLdap, long time) {
return makeAuditStamp(new CorpuserUrn(actorLdap), null, time);
}
@Nonnull
public static AuditStamp makeAuditStamp(@Nonnull String actorLdap) {
return makeAuditStamp(actorLdap, 0L);
}
}

View File

@ -0,0 +1,65 @@
package com.linkedin.metadata.testing;
import com.linkedin.common.Owner;
import com.linkedin.common.OwnerArray;
import com.linkedin.common.Ownership;
import com.linkedin.common.OwnershipSource;
import com.linkedin.common.OwnershipSourceType;
import com.linkedin.common.OwnershipSuggestion;
import com.linkedin.common.OwnershipType;
import com.linkedin.common.urn.CorpuserUrn;
import com.linkedin.common.urn.Urn;
import com.linkedin.metadata.aspect.MetricAspect;
import java.util.Collections;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public final class Owners {
private Owners() {
}
@Nonnull
public static Owner makeOwner(@Nonnull String ldap) {
return makeOwner(ldap, OwnershipType.DEVELOPER);
}
@Nonnull
public static Owner makeOwner(@Nonnull String ldap, @Nonnull OwnershipType type) {
return new Owner().setOwner(new CorpuserUrn(ldap)).setType(type);
}
@Nonnull
public static Owner makeOwner(@Nonnull Urn ownerUrn, @Nonnull OwnershipType type,
@Nullable OwnershipSourceType sourceType, @Nullable String sourceUrl) {
Owner owner = new Owner().setOwner(ownerUrn).setType(type);
if (sourceType != null) {
OwnershipSource source = new OwnershipSource().setType(sourceType);
if (sourceUrl != null) {
source.setUrl(sourceUrl);
}
owner.setSource(source);
}
return owner;
}
@Nonnull
public static Ownership makeOwnership(@Nonnull String ldap) {
return new Ownership().setOwners(new OwnerArray(Collections.singleton(makeOwner(ldap))));
}
@Nonnull
public static OwnershipSuggestion makeOwnershipSuggestion(@Nonnull String ldap) {
return new OwnershipSuggestion().setOwners(new OwnerArray(Collections.singleton(makeOwner(ldap))));
}
@Nonnull
public static MetricAspect makeOwnershipAspectUnion(@Nonnull String ldap) {
MetricAspect aspect = new MetricAspect();
aspect.setOwnership(makeOwnership(ldap));
return aspect;
}
}

View File

@ -0,0 +1,64 @@
package com.linkedin.metadata.testing;
import com.linkedin.common.FabricType;
import com.linkedin.common.RegisteredSchemaType;
import com.linkedin.common.urn.CorpGroupUrn;
import com.linkedin.common.urn.CorpuserUrn;
import com.linkedin.common.urn.DatasetGroupUrn;
import com.linkedin.common.urn.DatasetUrn;
import com.linkedin.common.urn.FeatureUrn;
import com.linkedin.common.urn.MetricUrn;
import com.linkedin.common.urn.RegisteredSchemaUrn;
import com.linkedin.metadata.urn.InternalDataPlatformUrn;
import com.linkedin.metadata.urn.InternalDatasetUrn;
import com.linkedin.metadata.urn.InternalRegisteredSchemaUrn;
import javax.annotation.Nonnull;
/**
* Utilities related to URNs for testing.
*/
public final class Urns {
private Urns() {
}
@Nonnull
public static CorpuserUrn makeCorpUserUrn(@Nonnull String name) {
return new CorpuserUrn(name);
}
@Nonnull
public static CorpGroupUrn makeCorpGroupUrn(@Nonnull String name) {
return new CorpGroupUrn(name);
}
@Nonnull
public static DatasetUrn makeDatasetUrn(@Nonnull String name) {
return new InternalDatasetUrn(new InternalDataPlatformUrn("mysql"), name, FabricType.DEV);
}
@Nonnull
public static DatasetUrn makeDatasetUrn(@Nonnull String platform, @Nonnull String name, @Nonnull FabricType fabricType) {
return new InternalDatasetUrn(new InternalDataPlatformUrn(platform), name, fabricType);
}
@Nonnull
public static MetricUrn makeMetricUrn(@Nonnull String name) {
return new MetricUrn("UMP", name);
}
@Nonnull
public static DatasetGroupUrn makeDatasetGroupUrn(@Nonnull String name) {
return new DatasetGroupUrn("foo", name);
}
@Nonnull
public static RegisteredSchemaUrn makeRegisteredSchemaUrn(@Nonnull String name) {
return new InternalRegisteredSchemaUrn(RegisteredSchemaType.KAFKA, name);
}
@Nonnull
public static FeatureUrn makeFeatureUrn(@Nonnull String name) {
return new FeatureUrn("foo", name);
}
}