package de.paymill.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

import de.paymill.Paymill;
import de.paymill.TestCase;
import de.paymill.model.Client;
import de.paymill.model.Offer;
import de.paymill.model.Payment;
import de.paymill.model.Subscription;
import de.paymill.net.ApiException;

public class SubscriptionServiceTest extends TestCase {

	@Test
	public void testCreateSubscription() {
		SubscriptionService srv = Paymill.getService(SubscriptionService.class);
		Offer offer = new Offer();
		offer.setId("offer_12345");
		Client client = new Client();
		client.setId("client_12345");
		Payment pay = new Payment();
		pay.setId("pay_12345");
		
		Subscription params = new Subscription();
		params.setOffer(offer);
		params.setClient(client);
		params.setPayment(pay);

		try {
			srv.create(params);
			fail("Expected exception");
		} catch(ApiException ex) {
			assertEquals("offer_not_found", ex.getCode());
		}
	}
}

@@ -101,19 +101,28 @@
 .Assert.
-fai
+assertNotNul
 l;%0D%0A%0D%0Aim
@@ -291,23 +291,103 @@
 l.model.
-Payment
+Offer.Interval;%0D%0Aimport de.paymill.model.Payment;%0D%0Aimport de.paymill.model.Payment.Type
 ;%0D%0Aimpor
@@ -423,45 +423,8 @@
 on;%0D
-%0Aimport de.paymill.net.ApiException;%0D
 %0A%0D%0Ap
@@ -530,16 +530,226 @@
 on() %7B%0D%0A
+%09%09OfferService srvOffer = Paymill.getService(OfferService.class);%0D%0A%09%09ClientService srvClient = Paymill.getService(ClientService.class);%0D%0A%09%09PaymentService srvPayment = Paymill.getService(PaymentService.class);%0D%0A
 %09%09Subscr
@@ -765,16 +765,20 @@
 vice srv
+Subs
  = Paymi
@@ -820,16 +820,18 @@
 lass);%0D%0A
+%0D%0A
 %09%09Offer 
@@ -867,94 +867,298 @@
 .set
-Id(%22offer_12345%22);%0D%0A%09%09Client client = new Client();%0D%0A%09%09client.setId(%22client_12345%22
+Amount(199);%0D%0A%09%09offer.setInterval(Interval.WEEK);%0D%0A%09%09offer.setName(%22testabo%22);%0D%0A%09%09offer.setTrialPeriodDays(15);%0D%0A%09%09offer.setCurrency(%22eur%22);%0D%0A%09%09offer = srvOffer.create(offer);%0D%0A%0D%0A%09%09Client client = new Client();%0D%0A%09%09client.setEmail(getRandomEmail());%0D%0A%09%09client = srvClient.create(client
 );%0D%0A
+%0D%0A
 %09%09Pa
@@ -1166,16 +1166,20 @@
 ment pay
+ment
  = new P
@@ -1198,32 +1198,212 @@
 %09pay
-.setId(%22pay_
+ment.setType(Type.DEBIT);%0D%0A%09%09payment.setAccount(%22123456%22);%0D%0A%09%09payment.setCode(%22
 12345
+678
 %22);%0D%0A%09%09
+payment.setHolder(%22jon doe%22);%0D%0A%09%09payment.setClient(client.getId());%0D%0A%09%09payment = srvPayment.create(payment);%0D%0A
 %0D%0A%09%09
@@ -1415,21 +1415,19 @@
 ription 
-param
+sub
 s = new 
@@ -1441,29 +1441,27 @@
 ption();%0D%0A%09%09
-param
+sub
 s.setOffer(o
@@ -1466,29 +1466,27 @@
 (offer);%0D%0A%09%09
-param
+sub
 s.setClient(
@@ -1497,21 +1497,19 @@
 nt);%0D%0A%09%09
-param
+sub
 s.setPay
@@ -1520,110 +1520,165 @@
 (pay
-);%0D%0A%0D%0A%09%09try %7B%0D%0A%09%09%09srv.create(params);%0D%0A%09%09%09fail(%22Expected exception%22);%0D%0A%09%09%7D catch(ApiException ex) %7B
+ment);%0D%0A%09%09subs = srvSubs.create(subs);%0D%0A%0D%0A%09%09assertNotNull(subs);%0D%0A%09%09assertNotNull(subs.getId());%0D%0A%09%09assertEquals(subs.getClient().getId(), client.getId());
 %0D%0A
-%09
 %09%09as
@@ -1692,46 +1692,109 @@
 als(
-%22offer_not_found%22, ex.getCode());%0D%0A%09%09%7D
+subs.getOffer().getId(), offer.getId());%0D%0A%09%09assertEquals(subs.getPayment().getId(), payment.getId());
 %0D%0A%09%7D

Add create test to subscription service