Skip to content

Commit

Permalink
fix(cloudfoundry): Remove lombok generated getter (#5616)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergio Quintero <sergio.quintero@armory.io>
  • Loading branch information
link108 and sergio-quintero committed Jan 19, 2022
1 parent 8c1e9ec commit 4aab0d8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -80,6 +81,8 @@ public class CloudFoundryCredentials extends AbstractAccountCredentials<CloudFou
private final Permissions permissions;
private final ForkJoinPool forkJoinPool;
private final List<CloudFoundrySpace> filteredSpaces;

@Getter(AccessLevel.NONE)
private final CloudFoundryClient cloudFoundryClient;

public CloudFoundryCredentials(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@

import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.netflix.spinnaker.clouddriver.cloudfoundry.cache.CacheRepository;
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClient;
Expand All @@ -38,6 +42,7 @@
import java.util.concurrent.ForkJoinPool;
import okhttp3.OkHttpClient;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class CloudFoundryCredentialsTest {
Expand Down Expand Up @@ -121,6 +126,41 @@ void fakeOrgFakeSpaceSpaceFilterShouldThrowError() {
"The spaceFilter had Orgs and/or Spaces but CloudFoundry returned no spaces as a result. Spaces must not be null or empty when a spaceFilter is included.");
}

@Test
@DisplayName(
"Tests Jackson Ignore Annotations. These fields should not be serialized when calling '/credentials'")
void testJacksonSerialization() throws NoSuchMethodException {
// these constructors should exist
assertNotNull(CloudFoundryCredentials.class.getMethod("getCredentials"));
assertNotNull(CloudFoundryCredentials.class.getMethod("getClient"));
assertNotNull(CloudFoundryCredentials.class.getMethod("getPassword"));
assertNotNull(CloudFoundryCredentials.class.getMethod("getSpaceSupplier"));
assertNotNull(CloudFoundryCredentials.class.getMethod("getCacheRepository"));
assertNotNull(CloudFoundryCredentials.class.getMethod("getForkJoinPool"));
assertNotNull(CloudFoundryCredentials.class.getMethod("getFilteredSpaces"));
assertNotNull(CloudFoundryCredentials.class.getDeclaredMethod("getSpacesLive"));

// lombok shouldn't generate an additional constructor for the "cloudFoundryClient" field
assertThrows(
NoSuchMethodException.class,
() -> CloudFoundryCredentials.class.getMethod("getCloudFoundryClient"));

ObjectMapper mapper = new ObjectMapper();
CloudFoundryCredentials credentials = getStubCloudFoundryCredentials();
// Test Jackson Annotations
JsonNode jsonCredentials = mapper.valueToTree(credentials);

assertFalse(jsonCredentials.has("credentials"));
assertFalse(jsonCredentials.has("client"));
assertFalse(jsonCredentials.has("cloudFoundryClient"));
assertFalse(jsonCredentials.has("password"));
assertFalse(jsonCredentials.has("spaceSupplier"));
assertFalse(jsonCredentials.has("cacheRepository"));
assertFalse(jsonCredentials.has("forkJoinPool"));
assertFalse(jsonCredentials.has("filteredSpaces"));
assertFalse(jsonCredentials.has("spacesLive"));
}

@NotNull
private CloudFoundryCredentials getStubCloudFoundryCredentials() {
return new CloudFoundryCredentials(
Expand Down

0 comments on commit 4aab0d8

Please sign in to comment.