Skip to content

Commit

Permalink
APPNG-2442 Applied codestyle formaters.
Browse files Browse the repository at this point in the history
  • Loading branch information
dheuvels committed Jul 19, 2022
1 parent 0061ebe commit b13236d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
51 changes: 30 additions & 21 deletions appng-api/src/test/java/org/appng/api/RequestMappingTest.java
Expand Up @@ -39,21 +39,22 @@ public class RequestMappingTest {

@Mock
private Environment env;

@Mock
Properties platformProperties;


@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Mockito.when(env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG)).thenReturn(platformProperties);
Mockito.when(env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG))
.thenReturn(platformProperties);

Map<String, Site> siteMap = new HashMap<>();
Site site1 = Mockito.mock(Site.class);
Mockito.when(site1.getName()).thenReturn("site1");
Mockito.when(site1.getHost()).thenReturn("site1.loc");
Mockito.when(site1.getHostAliases()).thenReturn(new HashSet<String>(Arrays.asList("alias1-1.loc", "alias1-2.loc", "alias1-2.loc")));
Mockito.when(site1.getHostAliases())
.thenReturn(new HashSet<String>(Arrays.asList("alias1-1.loc", "alias1-2.loc", "alias1-2.loc")));
siteMap.put(site1.getName(), site1);

Site site2 = Mockito.mock(Site.class);
Expand All @@ -70,13 +71,14 @@ public void setUp() {

Mockito.when(env.getAttribute(Scope.PLATFORM, Platform.Environment.SITES)).thenReturn(siteMap);
}

@Test
public void testSiteMappingIPBasedMatchHost() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getLocalAddr()).thenReturn("127.0.47.11");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.IP_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.IP_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site2");
}
Expand All @@ -85,8 +87,9 @@ public void testSiteMappingIPBasedMatchHost() throws Exception {
public void testSiteMappingIPBasedMatchHostAlias() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getLocalAddr()).thenReturn("127.0.47.12");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.IP_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.IP_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site2");
}
Expand All @@ -95,8 +98,9 @@ public void testSiteMappingIPBasedMatchHostAlias() throws Exception {
public void testSiteMappingIPBasedMiss() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getLocalAddr()).thenReturn("1.2.3.4");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.IP_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.IP_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertNull(site);
}
Expand All @@ -105,8 +109,9 @@ public void testSiteMappingIPBasedMiss() throws Exception {
public void testSiteMappingNameBasedMatchHost() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getServerName()).thenReturn("site3.loc");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.NAME_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.NAME_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site3");
}
Expand All @@ -115,8 +120,9 @@ public void testSiteMappingNameBasedMatchHost() throws Exception {
public void testSiteMappingNameBasedMatchHostAlias() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getServerName()).thenReturn("alias1-2.loc");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.NAME_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.NAME_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site1");
}
Expand All @@ -125,8 +131,9 @@ public void testSiteMappingNameBasedMatchHostAlias() throws Exception {
public void testSiteMappingDirectMatchSERVER_LOCAL_NAME() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getAttribute(RequestUtil.SERVER_LOCAL_NAME)).thenReturn("site1");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.NAME_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.NAME_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site1");
}
Expand All @@ -135,8 +142,9 @@ public void testSiteMappingDirectMatchSERVER_LOCAL_NAME() throws Exception {
public void testSiteMappingDirectMatchX_APPNG_SITE() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getHeader(RequestUtil.X_APPNG_SITE)).thenReturn("site2");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.NAME_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.NAME_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site2");
}
Expand All @@ -146,8 +154,9 @@ public void testSiteMappingDirectMatchPriority() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getAttribute(RequestUtil.X_APPNG_SITE)).thenReturn("site3");
Mockito.when(request.getAttribute(RequestUtil.SERVER_LOCAL_NAME)).thenReturn("site1");
Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE)).thenReturn(VHostMode.NAME_BASED.toString());

Mockito.when(platformProperties.getString(Platform.Property.VHOST_MODE))
.thenReturn(VHostMode.NAME_BASED.toString());

Site site = RequestUtil.getSite(env, request);
Assert.assertEquals(site.getName(), "site1");
}
Expand Down
3 changes: 1 addition & 2 deletions appng-core/src/main/java/org/appng/core/domain/SiteImpl.java
Expand Up @@ -183,8 +183,7 @@ public void setHost(String host) {
// Sites are fetched in different transactions and reused all over the place. Since there is no performance gain
// in lazy-fetching the small amount of aliases, we agreed on eager fetching with MM.
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "site_hostalias", joinColumns = @JoinColumn(name = "site_id", referencedColumnName = "id"),
foreignKey = @ForeignKey(name = "FK__SITE_HOSTALIAS__SITE"))
@CollectionTable(name = "site_hostalias", joinColumns = @JoinColumn(name = "site_id", referencedColumnName = "id"), foreignKey = @ForeignKey(name = "FK__SITE_HOSTALIAS__SITE"))
@Column(name = "hostname", unique = true)
public Set<String> getHostAliases() {
return hostAliases;
Expand Down
Expand Up @@ -44,7 +44,7 @@ public interface SiteRepository extends SearchRepository<SiteImpl, Integer> {

@Query("select distinct s from SiteImpl s join s.hostAliases a where ( s.host in (?1) or a in (?1) )")
List<SiteImpl> findSitesForHostNames(Set<String> hostNames);

List<SiteImpl> findByNameIn(Iterable<String> siteNames);

}
Expand Up @@ -178,8 +178,8 @@ protected void testInitDatabaseMsSql(String imageVersion, String productVersion)
try (MSSQLServerContainer<?> mssql = new MSSQLServerContainer<>(
"mcr.microsoft.com/mssql/server:" + imageVersion)) {
mssql.start();
validateConnectionType(mssql, DatabaseType.MSSQL, "Microsoft SQL Server", productVersion, "", "4.4",
false, false);
validateConnectionType(mssql, DatabaseType.MSSQL, "Microsoft SQL Server", productVersion, "", "4.4", false,
false);
}
}

Expand Down

0 comments on commit b13236d

Please sign in to comment.