Search in sources :

Example 1 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebEndpointTest method invokeWithEmptyUserRoles.

@Test
public void invokeWithEmptyUserRoles() {
    CoffeeNetWebUser coffeeNetWebUser = new CoffeeNetWebUser("username", "email");
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("NoRights", "urlNoRights", emptySet());
    List<CoffeeNetApp> coffeeNetApps = singletonList(coffeeNetApp);
    CoffeeNetWeb coffeeNetWeb = new CoffeeNetWeb(coffeeNetWebUser, coffeeNetApps, coffeeNetApp, "path");
    when(coffeeNetWebServiceMock.get()).thenReturn(coffeeNetWeb);
    CoffeeNetWebEndpoint sut = new CoffeeNetWebEndpoint(coffeeNetWebServiceMock);
    CoffeeNetWeb receivedCoffeeNetWeb = sut.invoke();
    assertThat(receivedCoffeeNetWeb.getCoffeeNetApps(), is(coffeeNetApps));
    assertThat(receivedCoffeeNetWeb.getCoffeeNetWebUser(), Is.is(coffeeNetWebUser));
    assertThat(receivedCoffeeNetWeb.getLogoutPath(), is("path"));
    assertThat(receivedCoffeeNetWeb.getProfileApp(), is(coffeeNetApp));
}
Also used : CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) Test(org.junit.Test)

Example 2 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebExtractorTest method extractApps.

@Test
public void extractApps() {
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    apps.put("cna1", singletonList(coffeeNetApp));
    CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
    apps.put("profile", singletonList(profileApp));
    sut.registerService(APP_SERVICE, coffeeNetAppServiceMock);
    when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
    // user
    sut.registerService(USER_SERVICE, coffeeNetCurrentUserServiceMock);
    List<GrantedAuthority> authorities = singletonList(new SimpleGrantedAuthority("ROLE_COFFEENET-ADMIN"));
    Optional<CoffeeNetUserDetails> user = of(new HumanCoffeeNetUser("username", "email", authorities));
    when(coffeeNetCurrentUserServiceMock.get()).thenReturn(user);
    Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
    assertThat(coffeeNetApps).hasSize(2);
    assertThat(coffeeNetApps.get("apps")).hasSize(1);
    assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
    assertThat(coffeeNetApps.get("profile")).hasSize(1);
    assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp);
}
Also used : HashMap(java.util.HashMap) HumanCoffeeNetUser(coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) CoffeeNetUserDetails(coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebExtractorTest method extractNoUserService.

@Test
public void extractNoUserService() {
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    apps.put("cna1", singletonList(coffeeNetApp));
    CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
    apps.put("profile", singletonList(profileApp));
    sut.registerService(APP_SERVICE, coffeeNetAppServiceMock);
    when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
    Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
    assertThat(coffeeNetApps).hasSize(2);
    assertThat(coffeeNetApps.get("apps")).hasSize(1);
    assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
    assertThat(coffeeNetApps.get("profile")).hasSize(1);
    assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp);
}
Also used : HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebExtractorTest method extractAppsNoProfile.

@Test
public void extractAppsNoProfile() {
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    apps.put("apps", singletonList(coffeeNetApp));
    sut.registerService(APP_SERVICE, coffeeNetAppServiceMock);
    when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
    // user
    sut.registerService(USER_SERVICE, coffeeNetCurrentUserServiceMock);
    List<GrantedAuthority> authorities = singletonList(new SimpleGrantedAuthority("ROLE_COFFEENET-ADMIN"));
    Optional<CoffeeNetUserDetails> user = of(new HumanCoffeeNetUser("username", "email", authorities));
    when(coffeeNetCurrentUserServiceMock.get()).thenReturn(user);
    Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
    assertThat(coffeeNetApps).hasSize(1);
    assertThat(coffeeNetApps.get("apps")).hasSize(1);
    assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
    assertThat(coffeeNetApps.get("profile")).isNull();
}
Also used : HashMap(java.util.HashMap) HumanCoffeeNetUser(coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) CoffeeNetUserDetails(coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with CoffeeNetApp

use of coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp in project coffeenet-starter by coffeenet.

the class CoffeeNetWebExtractorTest method extractAppsNoUser.

@Test
public void extractAppsNoUser() {
    Map<String, List<CoffeeNetApp>> apps = new HashMap<>();
    CoffeeNetApp coffeeNetApp = new CoffeeNetApp("Coffee App", "coffeeapp.coffeenet", emptySet());
    CoffeeNetApp coffeeNetApp2 = new CoffeeNetApp("Coffee App2", "coffeeapp.coffeenet", new HashSet<>(singletonList("ROLE_COFFEENET-USER")));
    apps.put("cna1", singletonList(coffeeNetApp));
    apps.put("cna2", singletonList(coffeeNetApp2));
    CoffeeNetApp profileApp = new CoffeeNetApp("Profile", "profile.coffeenet", emptySet());
    apps.put("profile", singletonList(profileApp));
    sut.registerService(APP_SERVICE, coffeeNetAppServiceMock);
    when(coffeeNetAppServiceMock.getApps(any())).thenReturn(apps);
    // user
    sut.registerService(USER_SERVICE, coffeeNetCurrentUserServiceMock);
    when(coffeeNetCurrentUserServiceMock.get()).thenReturn(Optional.empty());
    Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps();
    Map<String, List<CoffeeNetApp>> coffeeNetApps = extractedApps.get();
    assertThat(coffeeNetApps).hasSize(2);
    assertThat(coffeeNetApps.get("apps")).hasSize(2);
    assertThat(coffeeNetApps.get("apps").get(0)).isSameAs(coffeeNetApp);
    assertThat(coffeeNetApps.get("apps").get(1)).isSameAs(coffeeNetApp2);
    assertThat(coffeeNetApps.get("profile")).hasSize(1);
    assertThat(coffeeNetApps.get("profile").get(0)).isSameAs(profileApp);
}
Also used : HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) CoffeeNetApp(coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

CoffeeNetApp (coffee.synyx.autoconfigure.discovery.service.CoffeeNetApp)10 List (java.util.List)9 Collections.singletonList (java.util.Collections.singletonList)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 Map (java.util.Map)5 Collections.emptyList (java.util.Collections.emptyList)4 CoffeeNetUserDetails (coffee.synyx.autoconfigure.security.service.CoffeeNetUserDetails)3 HumanCoffeeNetUser (coffee.synyx.autoconfigure.security.service.HumanCoffeeNetUser)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)2 AppQuery (coffee.synyx.autoconfigure.discovery.service.AppQuery)1 Builder (coffee.synyx.autoconfigure.discovery.service.AppQuery.Builder)1 CoffeeNetAppService (coffee.synyx.autoconfigure.discovery.service.CoffeeNetAppService)1 CoffeeNetCurrentUserService (coffee.synyx.autoconfigure.security.service.CoffeeNetCurrentUserService)1 APP_SERVICE (coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.APP_SERVICE)1 USER_SERVICE (coffee.synyx.autoconfigure.web.CoffeeNetWebExtractor.CoffeeNetServices.USER_SERVICE)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 EnumMap (java.util.EnumMap)1