-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
platform/src/main/java/com/flickmatch/platform/proxy/WhatsAppProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.flickmatch.platform.proxy; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Service | ||
public class WhatsAppProxy { | ||
// Create a RestTemplate | ||
@Autowired | ||
private RestTemplate restTemplate; | ||
|
||
public void sendNotification() { | ||
String nodeServerUrl = "http://ec2-18-223-205-234.us-east-2.compute.amazonaws.com:3000/"; | ||
|
||
// Create headers | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
|
||
// Create the request payload | ||
String requestData = "{\"name\":\"John\",\"age\":30}"; | ||
HttpEntity<String> requestEntity = new HttpEntity<>(requestData, headers); | ||
|
||
// Make a POST request to the Node.js server | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(nodeServerUrl, String.class); | ||
// Print the response | ||
if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
String responseBody = responseEntity.getBody(); | ||
System.out.println("Response from Node.js server: " + responseBody); | ||
} else { | ||
System.err.println("Failed to post data to Node.js server"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
platform/src/test/java/com/flickmatch/platform/proxy/WhatsAppProxyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.flickmatch.platform.proxy; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class WhatsAppProxyTest { | ||
|
||
@Mock | ||
RestTemplate restTemplate; | ||
|
||
@InjectMocks WhatsAppProxy whatsAppProxy; | ||
|
||
@Test | ||
public void test_WhenCallIsSuccessful() { | ||
Mockito.when(restTemplate.getForEntity(anyString(), any())).thenReturn(ResponseEntity.accepted().build()); | ||
whatsAppProxy.sendNotification(); | ||
Mockito.verify(restTemplate).getForEntity(anyString(), any()); | ||
} | ||
|
||
@Test | ||
public void test_WhenCallFails() { | ||
Mockito.when(restTemplate.getForEntity(anyString(), any())).thenReturn(ResponseEntity.internalServerError().build()); | ||
whatsAppProxy.sendNotification(); | ||
Mockito.verify(restTemplate).getForEntity(anyString(), any()); | ||
} | ||
} |