Skip to content

Commit

Permalink
#19: Move tests to concepts package and change PUT to POST
Browse files Browse the repository at this point in the history
  • Loading branch information
Mats Stijlaart committed Oct 27, 2016
1 parent e1cfad2 commit cf7947e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/main/java/nl/stil4m/mollie/concepts/Customers.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ public ResponseOrError<Customer> create(CreateCustomer createCustomer) throws IO
}

public ResponseOrError<Customer> update(String customerId, UpdateCustomer updateCustomer) throws IOException {
HttpPut httpPut = new HttpPut(endpoint + "/customers/" + customerId);
System.out.println(requestExecutor.serialize(updateCustomer));
httpPut.setEntity(new StringEntity(requestExecutor.serialize(updateCustomer), ContentType.APPLICATION_JSON));
return requestExecutor.execute(apiKey, httpPut, new TypeReference<Customer>() {
HttpPost httpPost = new HttpPost(endpoint + "/customers/" + customerId);
httpPost.setEntity(new StringEntity(requestExecutor.serialize(updateCustomer), ContentType.APPLICATION_JSON));
return requestExecutor.execute(apiKey, httpPost, new TypeReference<Customer>() {
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package nl.stil4m.mollie;
package nl.stil4m.mollie.concepts;

import nl.stil4m.mollie.Client;
import nl.stil4m.mollie.ClientBuilder;
import nl.stil4m.mollie.ResponseOrError;
import nl.stil4m.mollie.domain.CreateCustomer;
import nl.stil4m.mollie.domain.CreatePayment;
import nl.stil4m.mollie.domain.Customer;
Expand All @@ -25,20 +28,19 @@
public class CustomerPaymentsIntegrationTest {

private Client client;
private Map<String,Object> defaultMetadata;
private Customer customer;

@Before
public void before() throws InterruptedException, IOException {
Thread.sleep(TEST_TIMEOUT);
client = new ClientBuilder().withApiKey(VALID_API_KEY).build();

defaultMetadata = new HashMap<>();
Map<String, Object> defaultMetadata = new HashMap<>();
defaultMetadata.put("foo", "bar");

String uuid = UUID.randomUUID().toString();
String name = "Test Customer " + uuid;
customer = client.customers().create(new CreateCustomer(name, "[email protected]", Optional.empty(), null)).getData();
customer = client.customers().create(new CreateCustomer(name, "[email protected]", Optional.empty(), defaultMetadata)).getData();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package nl.stil4m.mollie;
package nl.stil4m.mollie.concepts;

import nl.stil4m.mollie.Client;
import nl.stil4m.mollie.ClientBuilder;
import nl.stil4m.mollie.ResponseOrError;
import nl.stil4m.mollie.domain.CreateCustomer;
import nl.stil4m.mollie.domain.Customer;
import nl.stil4m.mollie.domain.Page;
Expand All @@ -19,10 +22,10 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public class CustomersIntegerationTest {
public class CustomersIntegrationTest {

private Client client;
private Map<String,Object> defaultMetadata;
private Map<String, Object> defaultMetadata;

@Before
public void before() throws InterruptedException {
Expand Down Expand Up @@ -57,22 +60,23 @@ public void testCreateCustomer() throws IOException, URISyntaxException {
}

@Test
public void testGetCustomer() throws IOException, URISyntaxException {
public void testGetCustomer() throws IOException, URISyntaxException {
String uuid = UUID.randomUUID().toString();
String originalName= "Test Customer " + uuid;
String originalName = "Test Customer " + uuid;
ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(originalName, "[email protected]", Optional.empty(), defaultMetadata));

ResponseOrError<Customer> fetchedCustomer = client.customers().get(createdCustomer.getData().getId());
assertThat(fetchedCustomer.getData().getName(),is(originalName));
assertThat(fetchedCustomer.getData().getName(), is(originalName));
//TODO Expand
}

@Test
public void testUpdateCustomer() throws IOException, URISyntaxException {
String uuid = UUID.randomUUID().toString();
String uuid2 = UUID.randomUUID().toString();
String originalName = "Test Customer " + uuid;
String newName = "Test Customer " + uuid2;
ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(originalName, "[email protected]", Optional.empty(), null));
ResponseOrError<Customer> createdCustomer = client.customers().create(new CreateCustomer(originalName, "[email protected]", Optional.empty(), null));

ResponseOrError<Customer> update = client.customers().update(createdCustomer.getData().getId(), new UpdateCustomer(
Optional.of(newName),
Expand Down

0 comments on commit cf7947e

Please sign in to comment.