Skip to content

Commit 02d9894

Browse files
committed
Adding unit tests
1 parent df70587 commit 02d9894

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2025 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.service.saveandrestore.filterselection;
6+
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.test.context.ContextConfiguration;
12+
import org.springframework.test.context.junit.jupiter.SpringExtension;
13+
14+
import static org.junit.jupiter.api.Assertions.*;
15+
16+
@ExtendWith(SpringExtension.class)
17+
@ContextConfiguration(classes = FilterSelectorTestConfig.class)
18+
public class FilterSelectorTest {
19+
20+
@Autowired
21+
private FilterSelector testFilterSelector;
22+
23+
@Autowired
24+
private FilterSelectionHandler filterSelectionHandler;
25+
26+
@Test
27+
public void testDiscoverFilterSelectors() {
28+
assertNotNull(testFilterSelector);
29+
}
30+
31+
@Test
32+
public void setTestFilterSelectorNames() {
33+
assertEquals("a", testFilterSelector.getSupportedFilterNames().get(0));
34+
assertEquals("b", testFilterSelector.getSupportedFilterNames().get(1));
35+
}
36+
37+
@Test
38+
public void testFilterSelectorHandler(){
39+
assertEquals(2, filterSelectionHandler.getSelectorFilterNames().size());
40+
}
41+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (C) 2018 European Spallation Source ERIC.
3+
* <p>
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
* <p>
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
* <p>
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
*/
18+
19+
package org.phoebus.service.saveandrestore.filterselection;
20+
21+
import co.elastic.clients.elasticsearch.ElasticsearchClient;
22+
import com.fasterxml.jackson.databind.ObjectMapper;
23+
import org.mockito.Mockito;
24+
import org.phoebus.saveandrestore.util.SnapshotUtil;
25+
import org.phoebus.service.saveandrestore.persistence.dao.NodeDAO;
26+
import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.ConfigurationDataRepository;
27+
import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.ElasticsearchTreeRepository;
28+
import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.FilterRepository;
29+
import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.SnapshotDataRepository;
30+
import org.phoebus.service.saveandrestore.search.SearchUtil;
31+
import org.phoebus.service.saveandrestore.web.config.AcceptHeaderResolver;
32+
import org.phoebus.service.saveandrestore.web.config.WebSecurityConfig;
33+
import org.phoebus.service.saveandrestore.websocket.WebSocketHandler;
34+
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.boot.SpringBootConfiguration;
36+
import org.springframework.context.annotation.Bean;
37+
import org.springframework.context.annotation.ComponentScan;
38+
import org.springframework.context.annotation.Import;
39+
import org.springframework.context.annotation.Profile;
40+
import org.springframework.util.Base64Utils;
41+
import org.springframework.web.socket.WebSocketSession;
42+
43+
import java.util.List;
44+
import java.util.concurrent.ExecutorService;
45+
import java.util.concurrent.Executors;
46+
47+
@SpringBootConfiguration
48+
@ComponentScan(basePackages = "org.phoebus.service.saveandrestore.filterselection")
49+
@SuppressWarnings("unused")
50+
@Profile("!IT")
51+
public class FilterSelectorTestConfig {
52+
53+
@Bean
54+
public FilterSelector testFilterSelector(){
55+
FilterSelector filterSelector = new FilterSelector() {
56+
@Override
57+
public List<String> getSupportedFilterNames() {
58+
return List.of("a", "b");
59+
}
60+
};
61+
return filterSelector;
62+
}
63+
64+
@Bean
65+
public WebSocketHandler webSocketHandler(){
66+
return Mockito.mock(WebSocketHandler.class);
67+
}
68+
69+
@Bean
70+
public ObjectMapper objectMapper(){
71+
return new ObjectMapper();
72+
}
73+
74+
@Bean
75+
public NodeDAO nodeDAO(){
76+
return Mockito.mock(NodeDAO.class);
77+
}
78+
}

0 commit comments

Comments
 (0)