Skip to content

Commit

Permalink
fix the injection issue and past the test through ao.space app.
Browse files Browse the repository at this point in the history
  • Loading branch information
ren2003u committed Sep 27, 2023
1 parent 9627ac2 commit c60d80a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.ren2003u.domain.errorHandle.ApiResponse;
import io.github.ren2003u.register.model.RegisterClientResponse;
import io.github.ren2003u.register.model.RegisterUserResponse;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.slf4j.Logger;
Expand All @@ -25,20 +26,28 @@ public class PlatformClient {
@Inject
ApplicationProperties properties;

private final String host = properties.ssplatformUrl();
private final Client client;
private String host;
private Client client;

private void init() {
if (this.client == null) {
this.host = properties.ssplatformUrl();
this.client = new Client(host, null);
}
}
private static final Logger LOG = LoggerFactory.getLogger(PlatformClient.class);

// Cache variables
private String cachedBoxRegKey = null;
private LocalDateTime lastFetchedTime = null;
private static final Duration CACHE_DURATION = Duration.ofMinutes(5); // Cache duration of 5 minutes

public PlatformClient() {
this.client = new Client(host, null);
}
// public PlatformClient() {
// this.client = new Client(host, null);
// }

public UserRegistryResult registerUser(String requestId, UserRegistryInfo userRegistryInfo) {
init();
try {
// Obtain BoxRegKey
String boxRegKey = obtainBoxRegKey(requestId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.example.authentication.model.ObtainBoxRegKeyResponse;
import org.example.client.Client;
import org.example.domain.errorHandle.ApiResponse;
import org.example.register.model.RegisterUserResponse;

import org.jboss.logging.Logger;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand Down Expand Up @@ -74,31 +71,7 @@ public class MockPlatformRegistryServiceRestClient implements PlatformRegistrySe
@Inject
PlatformRegistryService platformRegistryService;

@InjectMock
Client mockClient;

@Test
public void testRegistryUser() throws Exception {
// Given
String requestId = "e9993fc787d94b6c886cbaa340f9c0f4";
UserRegistryInfo userRegistryInfo = new UserRegistryInfo("1","","user_admin","5d5af871790b4922bca935f08109a531");
// ... set other properties of userRegistryInfo as needed ...

// Mock the SDK's methods
ObtainBoxRegKeyResponse mockObtainBoxRegKeyResponse = new ObtainBoxRegKeyResponse();
// ... set properties of mockObtainBoxRegKeyResponse as needed ...
Mockito.when(mockClient.obtainBoxRegKey(anyString(), anyList(), anyString())).thenReturn(new ApiResponse<>());

RegisterUserResponse mockRegisterUserResponse = new RegisterUserResponse();
// ... set properties of mockRegisterUserResponse as needed ...
Mockito.when(mockClient.registerUser(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(new ApiResponse<>());

// When
UserRegistryResult result = platformRegistryService.registryUser(requestId, userRegistryInfo, true);

// Then
// ... assert the expected behavior/results ...
}

@Override
public TokenCreateResults createTokens(TokenInfo tokenInfo, String reqId) {
Expand Down

0 comments on commit c60d80a

Please sign in to comment.