Skip to content

Commit

Permalink
Add test coverage for protocol conversion flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey committed Dec 13, 2024
1 parent 74be812 commit 105767b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@

package org.finos.legend.depot.services.pure.model.context;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.util.StdConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -73,8 +75,8 @@ public PureModelContextData getPureModelContextData(String groupId, String artif
List<ProjectVersionEntities> dependenciesEntities = this.entitiesService.getDependenciesEntities(groupId, artifactId, version, true, false);
return tracer.executeWithTrace(CALCULATE_COMBINED_PMCD, () ->
{
PureModelContextData dependenciesPMCD = buildPureModelContextData(dependenciesEntities.stream().flatMap(dep -> dep.getEntities().stream()),groupId,artifactId,version,resolvedClientVersion, convertToNewProtocol);
return combinePureModelContextData(pureModelContextData,dependenciesPMCD);
PureModelContextData dependenciesPMCD = buildPureModelContextData(dependenciesEntities.stream().flatMap(dep -> dep.getEntities().stream()), groupId, artifactId, version, resolvedClientVersion, convertToNewProtocol);
return combinePureModelContextData(pureModelContextData, dependenciesPMCD);
});
}

Expand Down Expand Up @@ -123,7 +125,7 @@ protected PureModelContextData combinePureModelContextData(PureModelContextData
protected AlloySDLC buildAlloySDLC(String groupId, String artifactId, String versionId)
{
AlloySDLC sdlc = new AlloySDLC();
sdlc.project = String.join(GA_SEPARATOR,groupId,artifactId);
sdlc.project = String.join(GA_SEPARATOR, groupId, artifactId);
sdlc.baseVersion = versionId;
return sdlc;
}
Expand All @@ -142,24 +144,26 @@ public Optional<PackageableElement> fromEntityIfPossible(Entity entity)
return Optional.of(this.fromEntity(entity));
}

@JsonSerialize(converter = EntityPackageableElementConverter.class)
private static class EntityPackageableElement extends PackageableElement
private static class EntityPackageableElement extends PackageableElement implements JsonSerializable
{
private final Entity entity;

public EntityPackageableElement(Entity entity)
{
this.entity = entity;
}
}
}

private static final class EntityPackageableElementConverter extends StdConverter<EntityToRawPureConverter.EntityPackageableElement, Map<String, ?>>
{
@Override
public Map<String, ?> convert(EntityToRawPureConverter.EntityPackageableElement value)
{
return value.entity.getContent();
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException
{
gen.writeObject(this.entity.getContent());
}

@Override
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException
{
gen.writeObject(this.entity.getContent());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setUpData()
@Test
public void loadPMCD()
{
Response data = resource.getPureModelContextData("test.legend", "blank-prod", "2.0.0", null, false,true, null);
Response data = resource.getPureModelContextData("test.legend", "blank-prod", "2.0.0", null, false,false, null);
Assert.assertFalse(((PureModelContextData)data.getEntity()).getElements().isEmpty());
Assert.assertEquals(((PureModelContextData)data.getEntity()).getElements().size(), 2);

Expand All @@ -77,7 +77,7 @@ public void loadPMCD()
@Test
public void loadDependenciesPMCD()
{
Response data = resource.getPureModelContextData(List.of(new ProjectVersion("org.finos.legend","second-project","1.0.1"), new ProjectVersion("org.finos.legend","first-project","1.0.2")), null, true, true, null);
Response data = resource.getPureModelContextData(List.of(new ProjectVersion("org.finos.legend","second-project","1.0.1"), new ProjectVersion("org.finos.legend","first-project","1.0.2")), null, true, false, null);
Assert.assertFalse(((PureModelContextData)data.getEntity()).getElements().isEmpty());
Assert.assertEquals(6, ((PureModelContextData)data.getEntity()).getElements().size());
Optional<Class> optionalPersonClass = ((PureModelContextData)data.getEntity())
Expand Down
Loading

0 comments on commit 105767b

Please sign in to comment.