@Before
	public void before() throws Exception {
		PageRequest pageable = new PageRequest(0, 20);
		Properties entityProps1 = new Properties();
		entityProps1.put("entity1", "value1");
		Properties entityProps2 = new Properties();
		entityProps2.put("entity2", "value2");
		Properties entityProps3 = new Properties();
		entityProps3.put("entity3", "value3");
		Properties deploymentProps1 = new Properties();
		deploymentProps1.put("count", "1");
		Properties deploymentProps2 = new Properties();
		deploymentProps2.put("count", "2");
		Properties deploymentProps3 = new Properties();
		deploymentProps3.put("criteria", "groups.contains('hdfs')");
		Stream stream1 = new Stream(new StreamDefinition("s1", "http | log"));
		stream1.setStatus(new DeploymentUnitStatus(State.deployed));
		ModuleMetadata entity1 = new ModuleMetadata(new ModuleMetadata.Id("1", "s1.source.http.0"),
				entityProps1, deploymentProps1, State.deployed);
		Stream stream2 = new Stream(new StreamDefinition("s2", "http | log"));
		stream1.setStatus(new DeploymentUnitStatus(State.failed));

		ModuleMetadata entity2 = new ModuleMetadata(new ModuleMetadata.Id("2", "s2.sink.log.1"),
				entityProps2, deploymentProps2, DeploymentUnitStatus.State.deployed);

		Job job1 = new Job(new JobDefinition("j3", "job"));
		job1.setStatus(new DeploymentUnitStatus(State.deployed));

		ModuleMetadata entity3 = new ModuleMetadata(new ModuleMetadata.Id("3", "j3.job.myjob.0"),
				entityProps3, deploymentProps3, State.deployed);
		List<ModuleMetadata> entities1 = new ArrayList<ModuleMetadata>();
		List<ModuleMetadata> entities2 = new ArrayList<ModuleMetadata>();
		List<ModuleMetadata> entities3 = new ArrayList<ModuleMetadata>();
		List<ModuleMetadata> all = new ArrayList<ModuleMetadata>();
		entities1.add(entity1);
		entities2.add(entity2);
		entities3.add(entity3);
		all.add(entity1);
		all.add(entity2);
		all.add(entity3);
		Page<ModuleMetadata> allPages = new PageImpl<>(all);
		Page<ModuleMetadata> pageEntity2 = new PageImpl<>(entities2);
		Page<ModuleMetadata> pageEntity3 = new PageImpl<>(entities3);
		when(moduleMetadataRepository.findAll(pageable)).thenReturn(allPages);
		when(moduleMetadataRepository.findAll()).thenReturn(all);
		when(moduleMetadataRepository.findAllByContainerId(pageable, "2")).thenReturn(pageEntity2);
		when(moduleMetadataRepository.findOne("1", "s1.source.http.0")).thenReturn(entity1);
		when(moduleMetadataRepository.findAllByModuleId(pageable, "j3.job.myjob.0")).thenReturn(pageEntity3);
		ModuleDefinition sinkDefinition = TestModuleDefinitions.dummy("sink", ModuleType.sink);
		ModuleDefinition sourceDefinition = TestModuleDefinitions.dummy("source", ModuleType.source);
		ModuleDefinition jobDefinition = TestModuleDefinitions.dummy("job", ModuleType.job);

		ArrayList<ModuleDefinition> definitions = new ArrayList<ModuleDefinition>();
		definitions.add(TestModuleDefinitions.dummy("source", ModuleType.source));
		when(moduleRegistry.findDefinitions("source")).thenReturn(definitions);
		when(moduleRegistry.findDefinitions("http")).thenReturn(definitions);
		when(moduleRegistry.findDefinition("http", ModuleType.source)).thenReturn(sourceDefinition);

		definitions = new ArrayList<ModuleDefinition>();
		definitions.add(TestModuleDefinitions.dummy("sink", ModuleType.sink));
		when(moduleRegistry.findDefinitions("sink")).thenReturn(definitions);
		when(moduleRegistry.findDefinitions("log")).thenReturn(definitions);
		when(moduleRegistry.findDefinition("log", ModuleType.sink)).thenReturn(sinkDefinition);

		definitions.add(TestModuleDefinitions.dummy("job", ModuleType.job));
		when(moduleRegistry.findDefinitions("job")).thenReturn(definitions);
		when(moduleRegistry.findDefinitions("job")).thenReturn(definitions);
		when(moduleRegistry.findDefinition("job", ModuleType.job)).thenReturn(jobDefinition);
		mockMvc.perform(
				post("/streams/definitions").param("name", stream1.getDefinition().getName()).param("definition",
						"http | log").param(
						"deploy", "true")
						.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
		assertNotNull(streamRepository.findOne(stream1.getDefinition().getName()));
		mockMvc.perform(
				post("/streams/definitions").param("name", stream2.getDefinition().getName()).param("definition",
						"http | log").param(
						"deploy", "true")
						.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
		assertNotNull(streamRepository.findOne(stream2.getDefinition().getName()));
		mockMvc.perform(
				post("/jobs/definitions").param("name", job1.getDefinition().getName()).param("definition",
						"job").param(
						"deploy", "true")
						.accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
		assertNotNull(jobRepository.findOne(job1.getDefinition().getName()));

	}
Tests REST compliance of module metadata endpoint.

@author Ilayaperumal Gopinathan
@author Gunnar Hillert
spring-xd-dirt/src/test/java/org/springframework/xd/dirt/rest/ModuleMetadataControllerIntegrationTests.java