package de.tse.simplerestfacade.example.consumer;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import javax.ws.rs.core.MediaType;

import de.tse.simplerestfacade.JerseyRestFacadeFactory;
import de.tse.simplerestfacade.RestFacadeFactory;
import de.tse.simplerestfacade.example.consumer.api.User;
import de.tse.simplerestfacade.example.consumer.api.UserService;
import de.tse.simplerestfacade.example.provider.RestServer;

public class RestClient {

	private final UserService userService;
	
	public RestClient(final String url) {
		
		final RestFacadeFactory factory = new JerseyRestFacadeFactory(url);
		this.userService = factory.createFacade(UserService.class, MediaType.APPLICATION_XML);
	}
	
	public void createUsers() {
		
		final List<User> users = Arrays.asList(new User("Max", "M."), 
											   new User("John", "D."),
											   new User("Emma", "W."));
		
		for (User user : users) {
			
			final User createdUser = userService.createUser(user);
			System.out.println("created: " + createdUser);
		}
	}
	
	public void loadAllUsers() {
		
		final User[] foundUsers = userService.findUser("Max", "M");
		for (User user : foundUsers) {
			System.out.println("found: " + user);
		}
	}
	
	public static void main(String[] args) throws IllegalArgumentException, IOException {
		
		final RestServer server = new RestServer("http://localhost:8080/restexample");
		server.start();
		
		final RestClient client = new RestClient("http://localhost:8080/restexample");
		client.createUsers();
		client.loadAllUsers();
		
		server.stop();
	}
}

@@ -899,16 +899,57 @@
 %22));%0A%09%09%0A
+%09%09System.out.println(%22Create users...%22);%0A
 %09%09for (U
@@ -1057,16 +1057,9 @@
 ln(%22
-created:
+ 
  %22 +
@@ -1099,24 +1099,150 @@
 oid 
-loadAllUsers() %7B
+findUsers(final String firstname, final String lastname) %7B%0A%09%09%0A%09%09System.out.println(%22Searching for '%22 + firstname + %22 %22 + lastname + %22' ... %22);
 %0A%09%09%0A
@@ -1294,18 +1294,27 @@
 ser(
-%22Max%22, %22M%22
+firstname, lastname
 );%0A%09
@@ -1372,14 +1372,9 @@
 ln(%22
-found:
+ 
  %22 +
@@ -1700,21 +1700,28 @@
 ent.
-loadAllUsers(
+findUsers(%22Max%22, %22M%22
 );%0A%09

change log output