Skip to content

Commit

Permalink
use version=2 for get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Jan 30, 2024
1 parent dd8768b commit 82bb9c8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,13 @@ download-ashwini-backup:
copy-backup-to-vagrant:
scp -P 2222 -i ~/.vagrant.d/insecure_private_key /tmp/abi-backup.sql [email protected]:/tmp/
#######

restore-ashwini-dump:
ifndef dumpFile
@echo "Provde the dumpFile variable"
exit 1
else
$(call _drop_db,avni_int_ashwini)
$(call _build_db,avni_int_ashwini)
psql -U bahmni_avni_admin -d avni_int_ashwini < $(dumpFile)
endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ public void toISODateString() {
public void fromAvniDate() {
Date date = FormatAndParseUtil.fromAvniDate("2020-05-25");
assertNotNull(date);
date = FormatAndParseUtil.fromAvniDate("2020-05-25T18:30:00.000Z");
assertNotNull(date);
}

@Test
public void fromAvniDateTime() {
Date date = FormatAndParseUtil.fromAvniDateTime("2021-01-14T08:11:29.012Z");
assertNotNull(date);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ public class AvniHttpClient {
private AuthenticationHelper helper;

public <T> ResponseEntity<T> get(String url, Map<String, String> queryParams, Class<T> returnType) {
URI uri = makeGetUri(url, queryParams);
return getResponseEntity(returnType, uri, HttpMethod.GET, null);
}

URI makeGetUri(String url, Map<String, String> queryParams) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiUrl(url));
for (var entry : queryParams.entrySet()) {
builder.queryParam(entry.getKey(), entry.getValue());
}

URI uri = builder.build().encode().toUri();
return getResponseEntity(returnType, uri, HttpMethod.GET, null);
return builder.build().encode().toUri();
}

private <T> ResponseEntity<T> getResponseEntity(Class<T> returnType, URI uri, HttpMethod method, String json) {
Expand Down Expand Up @@ -129,6 +133,6 @@ public String fetchAuthToken() {
}

private String apiUrl(String url) {
return String.format("%s%s", AVNI_API_URL, url);
return String.format("%s%s?version=2", AVNI_API_URL, url);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.bahmni_avni_integration.client;

import org.bahmni_avni_integration.AbstractIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.net.URI;
import java.util.HashMap;

import static org.junit.jupiter.api.Assertions.assertEquals;

@SpringBootTest
class AvniHttpClientTest extends AbstractIntegrationTest {
@Autowired
private AvniHttpClient avniHttpClient;

@Test
void makeGetUri() {
HashMap<String, String> queryParams = new HashMap<>() {{
put("foo", "bar");
}};
assertEquals("https://staging.avniproject.org/baz?version=2&foo=bar", avniHttpClient.makeGetUri("/baz", queryParams).toString());
assertEquals("https://staging.avniproject.org?version=2&foo=bar", avniHttpClient.makeGetUri("", queryParams).toString());
assertEquals("https://staging.avniproject.org/baz?version=2", avniHttpClient.makeGetUri("/baz", new HashMap<>()).toString());
}
}

0 comments on commit 82bb9c8

Please sign in to comment.