package com.dziga.backcom.test.api.v1;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLStreamException;

import org.junit.Rule;
import org.junit.Test;

import com.dziga.backcom.api.v1.CustomerApi;
import com.dziga.backcom.test.TestConstants;
import com.github.tomakehurst.wiremock.junit.WireMockRule;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

@SuppressWarnings("unused")
public class CustomerApiTest {
	@Rule
    public WireMockRule wireMockRule = new WireMockRule(8089);

	@Test
	public void test() throws KeyManagementException, InvalidKeyException, NoSuchAlgorithmException, JAXBException, URISyntaxException, IOException, XMLStreamException {
		stubFor(post(urlEqualTo("/v1/customers")).withHeader("Accept", equalTo("application/xml"))
				.willReturn(
	            aResponse()
	                .withStatus(200)
	                .withHeader("Content-Type", "application/xml")
	                .withBody(
	                    TestConstants.XML_HEADER 
	                            + "<Customer>"
	                            + "<id>1</id>"
	                            + "<firstname>John</firstname>"
	                            + "<lasttname>Doe</lasttname>" 
	                            + "<street>Backer street 3</street>"
	                            + "<city>London</city>"
	                            + "</Customer>")));
	
		CustomerApi customer = new CustomerApi();
		customer.setCustomerFirstName("John");
		customer.setCustomerLastName("Doe");
		customer.setCustomerStreet("Backer street 3");
		customer.setCustomerCity("London");
		
		customer.createNewCustomer();
	}
}

@@ -668,24 +668,75 @@
 Exception;%0A%0A
+%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0A
 import org.j
@@ -860,16 +860,77 @@
 stants;%0A
+import com.github.tomakehurst.wiremock.common.LocalNotifier;%0A
 import c
@@ -980,17 +980,16 @@
 ckRule;%0A
-%0A
 import s
@@ -1044,16 +1044,166 @@
 eMock.*;
+%0Aimport com.github.tomakehurst.wiremock.common.Slf4jNotifier;%0Aimport static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
 %0A%0A@Suppr
@@ -1259,19 +1259,18 @@
 t %7B%0A
+%09%0A
 %09@Rule%0A
-    
+%09
 publ
@@ -1321,280 +1321,570 @@
 ule(
-8089);%0A%0A%09@Test%0A%09public void test() throws KeyManagementException, InvalidKeyException, NoSuchAlgorithmException, JAXBException, URISyntaxException, IOException, XMLStreamException %7B%0A%09%09stubFor(post(urlEqualTo(%22/v1/customers%22)).withHeader(%22Accept%22, equalTo(%22application/xml%22
+wireMockConfig().port(8089).notifier(%0A%09        new Slf4jNotifier(true)));%0A%0A%09@Before%0A%09public void setUp() %7B%0A%09%09stubFor(post(urlEqualTo(%22/v1/customers%22)).withHeader(%22Accept%22, equalTo(%22application/xml%22))%0A%09%09%09%09.withRequestBody(matching(%0A%09%09%09%09%09%09%09%09%22.*%3CCustomer%3E.*%22%0A%09                            + %22.*%3Cfirstname%3EJohn%3C/firstname%3E%22%0A                        %09%09+ %22.*%3Clastname%3EDoe%3C/lastname%3E.*%22 %0A%09                            + %22.*%3Cstreet%3EBacker street 3%3C/street%3E.*%22%0A%09                            + %22.*%3Ccity%3ELondon%3C/city%3E.*%22 %0A%09                            + %22.*%3C/Customer%3E.*%22%0A%09%09%09%09%09%09
 ))%0A%09
@@ -2279,25 +2279,24 @@
     + %22%3Clast
-t
 name%3EDoe%3C/la
@@ -2297,17 +2297,16 @@
 oe%3C/last
-t
 name%3E%22 %0A
@@ -2473,16 +2473,206 @@
 r%3E%22)));%0A
+%09%7D%0A%09%0A%09@Test%0A%09public void customerApiPost() throws KeyManagementException, InvalidKeyException, NoSuchAlgorithmException, JAXBException, URISyntaxException, IOException, XMLStreamException %7B%0A
 %09%0A%09%09Cust
@@ -2911,13 +2911,275 @@
 omer();%0A
+%09%09%0A%09%09Assert.assertEquals(%22John%22, customer.getCustomerFirstName());%0A%09%09Assert.assertEquals(%22Doe%22, customer.getCustomerLastName());%0A%09%09Assert.assertEquals(%22Backer street 3%22, customer.getCustomerStreet());%0A%09%09Assert.assertEquals(%22London%22, customer.getCustomerCity());%0A
 %09%7D%0A%7D%0A

add post customer test