Skip to content

Commit 59836c0

Browse files
committed
Add PublicConfigurationControllerTests
1 parent 1473dd6 commit 59836c0

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2023 IEXEC BLOCKCHAIN TECH
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+
17+
package com.iexec.blockchain.config;
18+
19+
import com.iexec.blockchain.tool.ChainConfig;
20+
import com.iexec.common.config.PublicChainConfig;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.mockito.InjectMocks;
24+
import org.mockito.Mock;
25+
import org.mockito.MockitoAnnotations;
26+
import org.springframework.http.ResponseEntity;
27+
28+
import java.time.Duration;
29+
30+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
31+
import static org.mockito.Mockito.when;
32+
33+
class PublicConfigurationControllerTests {
34+
35+
@Mock
36+
ChainConfig chainConfig;
37+
38+
@InjectMocks
39+
PublicConfigurationController controller;
40+
41+
@BeforeEach
42+
void init() {
43+
MockitoAnnotations.openMocks(this);
44+
}
45+
46+
@Test
47+
void shouldReturnConfig() {
48+
int blockTime = 5;
49+
PublicChainConfig expectedConfig = PublicChainConfig
50+
.builder()
51+
.sidechain(true)
52+
.chainId(65535)
53+
.chainNodeUrl("http://localhost:8545")
54+
.iexecHubContractAddress("0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca")
55+
.blockTime(Duration.ofSeconds(blockTime))
56+
.build();
57+
when(chainConfig.getChainId()).thenReturn(expectedConfig.getChainId());
58+
when(chainConfig.isSidechain()).thenReturn(expectedConfig.isSidechain());
59+
when(chainConfig.getNodeAddress()).thenReturn(expectedConfig.getChainNodeUrl());
60+
when(chainConfig.getHubAddress()).thenReturn(expectedConfig.getIexecHubContractAddress());
61+
when(chainConfig.getBlockTime()).thenReturn(blockTime);
62+
ResponseEntity<PublicChainConfig> response = controller.getPublicChainConfig();
63+
assertThat(response.getBody())
64+
.isNotNull()
65+
.isEqualTo(expectedConfig);
66+
}
67+
68+
}

0 commit comments

Comments
 (0)