+ @Test
+ public void deleteOnboardingWidget_Authorization_Error() throws Exception {
+
+ String security_user = "user";
+ String security_pass = "password";
+ String wrong_pass = "wrong";
+ Long widgetId = new Long(1);
+
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + wrong_pass).getBytes()));
+ mockMvc.perform(MockMvcRequestBuilders.delete("/microservices/widgetCatalog/" + widgetId)
+ .header("Authorization", basic_auth)
+ ).andExpect(status().isUnauthorized());
+ }
+
+ @Test
+ public void getServiceIdByWidget_Authorization_error()throws Exception {
+
+ String security_user = "user";
+ String security_pass = "password";
+ String wrong_pass = "wrong";
+ Long widgetId = new Long(1);
+
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + wrong_pass).getBytes()));
+ mockMvc.perform(MockMvcRequestBuilders.get("/microservices/widgetCatalog/parameters/" + widgetId)
+ .header("Authorization", basic_auth)
+ ).andExpect(status().isUnauthorized());
+
+ }
+
+ @Test
+ public void getServiceIdByWidget_ValidAuthorization_NoError()throws Exception {
+
+ String security_user = "user";
+ String security_pass = "password";
+ Long widgetId = new Long(1);
+
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + security_pass).getBytes()));
+ mockMvc.perform(MockMvcRequestBuilders.get("/microservices/widgetCatalog/parameters/" + widgetId)
+ .header("Authorization", basic_auth));
+ ArgumentCaptor<Long> widgetServiceArg = ArgumentCaptor.forClass(Long.class);
+ ArgumentCaptor<Long> storageServiceArg = ArgumentCaptor.forClass(Long.class);
+
+ Mockito.verify(widgetService, times(1)).getServiceIdByWidget(widgetServiceArg.capture());
+ assertEquals(widgetServiceArg.getValue(), widgetId);
+ }
+
+
+ @Test
+ public void getWidgetByServiceIdt_Authorization_error()throws Exception {
+
+ String security_user = "user";
+ String security_pass = "password";
+ String wrong_pass = "wrong";
+ Long serviceId = new Long(1);
+
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + wrong_pass).getBytes()));
+ mockMvc.perform(MockMvcRequestBuilders.get("/microservices/widgetCatalog/service/" + serviceId)
+ .header("Authorization", basic_auth)
+ ).andExpect(status().isUnauthorized());
+
+ }
+
+ @Test
+ public void getWidgetByServiceIdt_ValidAuthorization_Noerror()throws Exception {
+
+ Long serviceId = new Long(1);
+
+ List<WidgetCatalog> list = new ArrayList<WidgetCatalog>();
+ WidgetCatalog widget = new WidgetCatalog();
+ widget.setId(1);
+ widget.setName("junit");
+ list.add(widget);
+ Mockito.lenient().when(widgetService.getWidgetsByServiceId(serviceId)).thenReturn(list);
+
+ String security_user = "user";
+ String security_pass = "password";
+
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + security_pass).getBytes()));
+ mockMvc.perform(get("/microservices/widgetCatalog/service/"+serviceId).header("Authorization", basic_auth))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$[0].id", is(1)))
+ .andExpect(jsonPath("$[0].name", is("junit")));
+
+ }
+
+ @Test
+ public void getWidgetZipFile_Authorization_error()throws Exception {
+
+ String security_user = "user";
+ String security_pass = "password";
+ String wrong_pass = "wrong";
+ Long widgetId = new Long(1);
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + wrong_pass).getBytes()));
+ mockMvc.perform(MockMvcRequestBuilders.get("/microservices/download/" + widgetId)
+ .header("Authorization", basic_auth)
+ ).andExpect(status().isUnauthorized());
+
+ }
+
+
+ @Test
+ public void getWidgetZipFile_ValidAuthorization_Noerror()throws Exception {
+
+ String security_user = "user";
+ String security_pass = "password";
+ String wrong_pass = "wrong";
+ Long widgetId = new Long(1);
+ byte[] bytes="Test".getBytes();
+ Mockito.lenient().when(storageService.getWidgetCatalogContent(widgetId)).thenReturn(bytes);
+
+ ReflectionTestUtils.setField(controller, "security_user", security_user, String.class);
+ ReflectionTestUtils.setField(controller, "security_pass", security_pass, String.class);
+
+ String basic_auth = "Basic " + new String(Base64.encodeBase64((security_user + ":" + security_pass).getBytes()));
+ mockMvc.perform(MockMvcRequestBuilders.get("/microservices/download/" + widgetId)
+ .header("Authorization", basic_auth)
+ ).andExpect(status().isOk());
+
+ }
+
+