Skip to content

Commit 86ba9e6

Browse files
dev-marekphiz71
authored andcommitted
test: add unit tests for portal navigation and page content repositories
1 parent d1e576d commit 86ba9e6

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright © 2015 The Gravitee team (http://gravitee.io)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.gravitee.repository.mongodb.management.upgrade.upgrader.index.portalnavigationindex;
17+
18+
import io.gravitee.repository.mongodb.management.upgrade.upgrader.index.Index;
19+
import io.gravitee.repository.mongodb.management.upgrade.upgrader.index.IndexUpgrader;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class PortalNavigationItemEnvironmentIdIndexUpgrader extends IndexUpgrader {
24+
25+
@Override
26+
protected Index buildIndex() {
27+
return Index.builder()
28+
.collection("portal_navigation_items")
29+
.key("environmentId", ascending())
30+
.name("portal_navigation_items_environment_idx")
31+
.build();
32+
}
33+
}

gravitee-apim-repository/gravitee-apim-repository-test/src/test/java/io/gravitee/repository/management/PortalNavigationItemRepositoryTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import io.gravitee.repository.management.model.PortalNavigationItem;
2121
import java.util.List;
22+
import java.util.Set;
2223
import org.junit.Test;
2324
import org.junit.jupiter.api.DisplayNameGeneration;
2425
import org.junit.jupiter.api.DisplayNameGenerator;
@@ -41,6 +42,37 @@ public void should_find_all_navigation_items_for_organization_and_environment()
4142
assertThat(items).anyMatch(i -> "nav-item-2".equals(i.getId()));
4243
}
4344

45+
@Test
46+
public void should_find_all_navigation_items_for_area_and_org_and_env() throws Exception {
47+
List<PortalNavigationItem> items = portalNavigationItemRepository.findAllByAreaAndOrganizationIdAndEnvironmentId(
48+
PortalNavigationItem.Area.TOP_NAVBAR,
49+
"org-1",
50+
"env-1"
51+
);
52+
53+
assertThat(items).isNotNull();
54+
assertThat(items).hasSize(1);
55+
assertThat(items.getFirst().getId()).isEqualTo("nav-item-2");
56+
}
57+
58+
@Test
59+
public void should_delete_all_navigation_items_for_organization() throws Exception {
60+
portalNavigationItemRepository.deleteByOrganizationId("org-1");
61+
62+
Set<PortalNavigationItem> remaining = portalNavigationItemRepository.findAll();
63+
assertThat(remaining).isNotNull();
64+
assertThat(remaining).noneMatch(i -> "org-1".equals(i.getOrganizationId()));
65+
}
66+
67+
@Test
68+
public void should_delete_all_navigation_items_for_environment() throws Exception {
69+
portalNavigationItemRepository.deleteByEnvironmentId("env-1");
70+
71+
Set<PortalNavigationItem> remaining = portalNavigationItemRepository.findAll();
72+
assertThat(remaining).isNotNull();
73+
assertThat(remaining).noneMatch(i -> "env-1".equals(i.getEnvironmentId()));
74+
}
75+
4476
@Test
4577
public void should_create_and_delete_navigation_item() throws Exception {
4678
PortalNavigationItem item = PortalNavigationItem.builder()

gravitee-apim-repository/gravitee-apim-repository-test/src/test/java/io/gravitee/repository/management/PortalPageContentRepositoryTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.gravitee.repository.management.model.PortalPageContent;
2222
import jakarta.inject.Inject;
2323
import java.util.List;
24+
import java.util.Set;
2425
import org.junit.Test;
2526
import org.junit.jupiter.api.DisplayNameGeneration;
2627
import org.junit.jupiter.api.DisplayNameGenerator;
@@ -63,4 +64,47 @@ public void should_create_and_delete_page_content() throws Exception {
6364
var maybeFound = portalPageContentRepository.findById(content.getId());
6465
assertThat(maybeFound.isPresent()).isFalse();
6566
}
67+
68+
@Test
69+
public void should_update_page_content() throws Exception {
70+
PortalPageContent existing = portalPageContentRepository.findById("page-content-1").orElse(null);
71+
assertThat(existing).isNotNull();
72+
73+
PortalPageContent toUpdate = PortalPageContent.builder()
74+
.id(existing.getId())
75+
.type(existing.getType())
76+
.configuration(existing.getConfiguration())
77+
.content("# Updated content")
78+
.build();
79+
80+
portalPageContentRepository.update(toUpdate);
81+
82+
PortalPageContent updated = portalPageContentRepository.findById(existing.getId()).orElse(null);
83+
assertThat(updated).isNotNull();
84+
assertThat(updated.getContent()).isEqualTo("# Updated content");
85+
}
86+
87+
@Test
88+
public void should_delete_all_by_type() throws Exception {
89+
// Ensure there are items of the type
90+
List<PortalPageContent> contentsBefore = portalPageContentRepository.findAllByType(PortalPageContent.Type.GRAVITEE_MARKDOWN);
91+
assertThat(contentsBefore).isNotNull();
92+
assertThat(contentsBefore).isNotEmpty();
93+
94+
portalPageContentRepository.deleteByType(PortalPageContent.Type.GRAVITEE_MARKDOWN);
95+
96+
Set<PortalPageContent> contentsAfter = portalPageContentRepository.findAll();
97+
assertThat(contentsAfter).isNotNull();
98+
assertThat(contentsAfter).doesNotContainAnyElementsOf(contentsBefore);
99+
}
100+
101+
@Test
102+
public void should_find_all_page_contents() throws Exception {
103+
Set<PortalPageContent> all = portalPageContentRepository.findAll();
104+
105+
assertThat(all).isNotNull();
106+
assertThat(all.size()).isGreaterThanOrEqualTo(2);
107+
assertThat(all).anyMatch(c -> "page-content-1".equals(c.getId()));
108+
assertThat(all).anyMatch(c -> "page-content-2".equals(c.getId()));
109+
}
66110
}

0 commit comments

Comments
 (0)