Skip to content

Commit

Permalink
♻️ : use correct Base64 type
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Aug 5, 2022
1 parent 70ee36e commit 6136241
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.gaia_app.modules.bo.TerraformModule;
import io.gaia_app.organizations.OAuth2User;
import io.gaia_app.organizations.User;
import org.bson.internal.Base64;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
Expand All @@ -19,6 +18,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Base64;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -62,7 +62,7 @@ void getReadmeContent_shouldCallTheApi_andServeDecodedContent(){

var requestCaptor = ArgumentCaptor.forClass(HttpEntity.class);

var githubFile = new RegistryFile(Base64.encode("# Module Readme".getBytes()) + "\n");
var githubFile = new RegistryFile(Base64.getEncoder().encodeToString("# Module Readme".getBytes()) + "\n");
var response = new ResponseEntity<>(githubFile, HttpStatus.OK);

when(restTemplate.exchange(
Expand Down Expand Up @@ -92,7 +92,7 @@ void getReadmeContent_shouldCallTheApiWithoutAuth_ifNoToken_andServeDecodedConte

var requestCaptor = ArgumentCaptor.forClass(HttpEntity.class);

var githubFile = new RegistryFile(Base64.encode("# Module Readme".getBytes()));
var githubFile = new RegistryFile(Base64.getEncoder().encodeToString("# Module Readme".getBytes()));
var response = new ResponseEntity<>(githubFile, HttpStatus.OK);

when(restTemplate.exchange(
Expand All @@ -119,7 +119,7 @@ void getReadmeContent_shouldCallTheApiWithoutAuth_ifNoOwner_andServeDecodedConte

var requestCaptor = ArgumentCaptor.forClass(HttpEntity.class);

var githubFile = new RegistryFile(Base64.encode("# Module Readme".getBytes()));
var githubFile = new RegistryFile(Base64.getEncoder().encodeToString("# Module Readme".getBytes()));
var response = new ResponseEntity<>(githubFile, HttpStatus.OK);

when(restTemplate.exchange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.gaia_app.registries.RegistryFile
import io.gaia_app.organizations.OAuth2User
import io.gaia_app.organizations.User
import org.assertj.core.api.Assertions.assertThat
import org.bson.internal.Base64
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient
Expand All @@ -18,6 +17,7 @@ import org.springframework.test.web.client.match.MockRestRequestMatchers.request
import org.springframework.test.web.client.response.MockRestResponseCreators.withStatus
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
import java.nio.charset.Charset
import java.util.*

@RestClientTest(GithubRegistryApi::class)
@AutoConfigureWebClient(registerRestTemplate = true)
Expand Down Expand Up @@ -95,7 +95,7 @@ class GithubRegistryApiTest{
val readmeContent = """
# Sample README.md
"""
val sampleResult = RegistryFile(content = Base64.encode(readmeContent.toByteArray(Charset.defaultCharset())))
val sampleResult = RegistryFile(content = Base64.getEncoder().encodeToString(readmeContent.toByteArray(Charset.defaultCharset())))
val detailsString = objectMapper.writeValueAsString(sampleResult)
server.expect(requestTo("https://api.github.com/repos/terraform-aws-modules/terraform-aws-rds/contents/README.md"))
.andExpect(header("Authorization", "Bearer johnstoken"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.gaia_app.modules.bo.TerraformModule;
import io.gaia_app.organizations.OAuth2User;
import io.gaia_app.organizations.User;
import org.bson.internal.Base64;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
Expand All @@ -19,6 +18,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.Base64;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -62,7 +62,7 @@ void getReadmeContent_shouldCallTheApi_andServeDecodedContent(){

var requestCaptor = ArgumentCaptor.forClass(HttpEntity.class);

var gitlabFile = new RegistryFile(Base64.encode("# Module Readme".getBytes()));
var gitlabFile = new RegistryFile(Base64.getEncoder().encodeToString("# Module Readme".getBytes()));
var response = new ResponseEntity<>(gitlabFile, HttpStatus.OK);

when(restTemplate.exchange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import io.gaia_app.registries.RegistryFile
import io.gaia_app.organizations.OAuth2User
import io.gaia_app.organizations.User
import org.assertj.core.api.Assertions.assertThat
import org.bson.internal.Base64
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient
Expand All @@ -16,6 +15,7 @@ import org.springframework.test.web.client.match.MockRestRequestMatchers.header
import org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo
import org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess
import java.nio.charset.Charset
import java.util.Base64


@RestClientTest(GitlabRegistryApi::class)
Expand Down Expand Up @@ -77,7 +77,7 @@ class GitlabRegistryApiTest{
val readmeContent = """
# Sample README.md
"""
val sampleResult = RegistryFile(content = Base64.encode(readmeContent.toByteArray(Charset.defaultCharset())))
val sampleResult = RegistryFile(content = Base64.getEncoder().encodeToString(readmeContent.toByteArray(Charset.defaultCharset())))
val detailsString = objectMapper.writeValueAsString(sampleResult)
server.expect(requestTo("https://gitlab.com/api/v4/projects/15689/repository/files/README.md?ref=master"))
.andExpect(header("Authorization", "Bearer johnstoken"))
Expand Down

0 comments on commit 6136241

Please sign in to comment.