// Path: spring-cloud-sockets/src/test/java/org/springframework/cloud/reactive/socket/common/User.java
// public class User implements Serializable {
// 	private String name;
// 	private String favoriteColor;
// 
// 	public User(){}
// 
// 	public User(String name, String favoriteColor) {
// 		this.name = name;
// 		this.favoriteColor = favoriteColor;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getFavoriteColor() {
// 		return favoriteColor;
// 	}
// 
// 	public void setFavoriteColor(String favoriteColor) {
// 		this.favoriteColor = favoriteColor;
// 	}
// 
// 	@Override
// 	public boolean equals(Object o) {
// 		if (this == o) return true;
// 		if (o == null || getClass() != o.getClass()) return false;
// 
// 		User user = (User) o;
// 
// 		if (name != null ? !name.equals(user.name) : user.name != null) return false;
// 		return favoriteColor != null ? favoriteColor.equals(user.favoriteColor) : user.favoriteColor == null;
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		int result = name != null ? name.hashCode() : 0;
// 		result = 31 * result + (favoriteColor != null ? favoriteColor.hashCode() : 0);
// 		return result;
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/JacksonConverter.java
// public class JacksonConverter extends AbstractConverter {
// 
// 	private ObjectMapper mapper = new ObjectMapper();
// 
// 	public JacksonConverter() {
// 		super(MimeTypeUtils.APPLICATION_JSON);
// 	}
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		try {
// 			return mapper.readValue(payload, targetType);
// 		}
// 		catch (IOException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		try {
// 			return mapper.writeValueAsBytes(target);
// 		}
// 		catch (JsonProcessingException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/SerializableConverter.java
// public class SerializableConverter extends AbstractConverter {
// 
// 	public SerializableConverter() {
// 		super(MimeType.valueOf("application/java-serialized-object"));
// 	}
// 
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		return SerializationUtils.deserialize(payload);
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		return SerializationUtils.serialize(target);
// 	}
// 
// 
// }


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import io.rsocket.util.PayloadImpl;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.cloud.reactive.socket.annotation.OneWayMapping;
import org.springframework.cloud.reactive.socket.annotation.Payload;
import org.springframework.cloud.reactive.socket.annotation.RequestManyMapping;
import org.springframework.cloud.reactive.socket.annotation.RequestOneMapping;
import org.springframework.cloud.reactive.socket.annotation.RequestStreamMapping;
import org.springframework.cloud.reactive.socket.common.User;
import org.springframework.cloud.reactive.socket.converter.JacksonConverter;
import org.springframework.cloud.reactive.socket.converter.SerializableConverter;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.MimeType;
import static org.assertj.core.api.Assertions.assertThat;
	}

	@Test
	public void requestOneHandler() throws Exception {
		User user = new User("Mary", "red");
		Mono<io.rsocket.Payload> invocationResult = this.handler.requestResponse(new PayloadImpl(converter.write(user), getMetadataBytes(MimeType.valueOf("application/json") ,"/redblue")));
		User result = invocationResult.map(payload -> {
			return (User)converter.read(payload.getDataUtf8().getBytes(), User.class);
		}).block();
		assertThat("blue").isEqualTo(result.getFavoriteColor());
	}



	@Test
	public void requestOneWrongPath() throws Exception {
		User user = new User("Mary", "red");
		Mono<io.rsocket.Payload> invocationResult = this.handler.requestResponse(new PayloadImpl(converter.write(user), getMetadataBytes(MimeType.valueOf("application/json") ,"/notfound")));
		invocationResult.doOnError(throwable -> { resultsQueue.offer(throwable);}).subscribe();
		assertThat(resultsQueue.poll()).isInstanceOf(Throwable.class);
	}


	@Test
	public void requestMany() throws Exception {
		Integer count = 10;
		Flux<io.rsocket.Payload> invocationResult = this.handler.requestStream(new PayloadImpl(converter.write(count), getMetadataBytes(MimeType.valueOf("application/json") ,"/requestMany")));
		List<Integer> results = invocationResult.map(payload -> (Integer)converter.read(payload.getDataUtf8().getBytes(), Integer.class)
		).collectList().block();

// Path: spring-cloud-sockets/src/test/java/org/springframework/cloud/reactive/socket/common/User.java
// public class User implements Serializable {
// 	private String name;
// 	private String favoriteColor;
// 
// 	public User(){}
// 
// 	public User(String name, String favoriteColor) {
// 		this.name = name;
// 		this.favoriteColor = favoriteColor;
// 	}
// 
// 	public String getName() {
// 		return name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// 	public String getFavoriteColor() {
// 		return favoriteColor;
// 	}
// 
// 	public void setFavoriteColor(String favoriteColor) {
// 		this.favoriteColor = favoriteColor;
// 	}
// 
// 	@Override
// 	public boolean equals(Object o) {
// 		if (this == o) return true;
// 		if (o == null || getClass() != o.getClass()) return false;
// 
// 		User user = (User) o;
// 
// 		if (name != null ? !name.equals(user.name) : user.name != null) return false;
// 		return favoriteColor != null ? favoriteColor.equals(user.favoriteColor) : user.favoriteColor == null;
// 	}
// 
// 	@Override
// 	public int hashCode() {
// 		int result = name != null ? name.hashCode() : 0;
// 		result = 31 * result + (favoriteColor != null ? favoriteColor.hashCode() : 0);
// 		return result;
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/JacksonConverter.java
// public class JacksonConverter extends AbstractConverter {
// 
// 	private ObjectMapper mapper = new ObjectMapper();
// 
// 	public JacksonConverter() {
// 		super(MimeTypeUtils.APPLICATION_JSON);
// 	}
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		try {
// 			return mapper.readValue(payload, targetType);
// 		}
// 		catch (IOException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		try {
// 			return mapper.writeValueAsBytes(target);
// 		}
// 		catch (JsonProcessingException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/SerializableConverter.java
// public class SerializableConverter extends AbstractConverter {
// 
// 	public SerializableConverter() {
// 		super(MimeType.valueOf("application/java-serialized-object"));
// 	}
// 
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		return SerializationUtils.deserialize(payload);
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		return SerializationUtils.serialize(target);
// 	}
// 
// 
// }


// Path: spring-cloud-sockets/src/test/java/org/springframework/cloud/reactive/socket/DispatchHandlerTests.java
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import io.rsocket.util.PayloadImpl;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.cloud.reactive.socket.annotation.OneWayMapping;
import org.springframework.cloud.reactive.socket.annotation.Payload;
import org.springframework.cloud.reactive.socket.annotation.RequestManyMapping;
import org.springframework.cloud.reactive.socket.annotation.RequestOneMapping;
import org.springframework.cloud.reactive.socket.annotation.RequestStreamMapping;
import org.springframework.cloud.reactive.socket.common.User;
import org.springframework.cloud.reactive.socket.converter.JacksonConverter;
import org.springframework.cloud.reactive.socket.converter.SerializableConverter;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.MimeType;
import static org.assertj.core.api.Assertions.assertThat;

	}

	@Test
	public void requestOneHandler() throws Exception {
		User user = new User("Mary", "red");
		Mono<io.rsocket.Payload> invocationResult = this.handler.requestResponse(new PayloadImpl(converter.write(user), getMetadataBytes(MimeType.valueOf("application/json") ,"/redblue")));
		User result = invocationResult.map(payload -> {
			return (User)converter.read(payload.getDataUtf8().getBytes(), User.class);
		}).block();
		assertThat("blue").isEqualTo(result.getFavoriteColor());
	}



	@Test
	public void requestOneWrongPath() throws Exception {
		User user = new User("Mary", "red");
		Mono<io.rsocket.Payload> invocationResult = this.handler.requestResponse(new PayloadImpl(converter.write(user), getMetadataBytes(MimeType.valueOf("application/json") ,"/notfound")));
		invocationResult.doOnError(throwable -> { resultsQueue.offer(throwable);}).subscribe();
		assertThat(resultsQueue.poll()).isInstanceOf(Throwable.class);
	}


	@Test
	public void requestMany() throws Exception {
		Integer count = 10;
		Flux<io.rsocket.Payload> invocationResult = this.handler.requestStream(new PayloadImpl(converter.write(count), getMetadataBytes(MimeType.valueOf("application/json") ,"/requestMany")));
		List<Integer> results = invocationResult.map(payload -> (Integer)converter.read(payload.getDataUtf8().getBytes(), Integer.class)
		).collectList().block();

		assertThat(results).size().isEqualTo(10);