Commit a22bef2e182f3ac21ecd410202d77895328f073c
1 parent
30e1c480
Was created first test to EntityViewController
Showing
4 changed files
with
134 additions
and
1 deletions
... | ... | @@ -41,7 +41,9 @@ import org.junit.Before; |
41 | 41 | import org.junit.Test; |
42 | 42 | |
43 | 43 | import com.fasterxml.jackson.core.type.TypeReference; |
44 | - | |
44 | +/** | |
45 | + * Created by Victor Basanets on 8/27/2017. | |
46 | + */ | |
45 | 47 | public abstract class BaseDeviceControllerTest extends AbstractControllerTest { |
46 | 48 | |
47 | 49 | private IdComparator<Device> idComparator = new IdComparator<>(); | ... | ... |
application/src/test/java/org/thingsboard/server/controller/BaseEntityViewControllerTest.java
0 → 100644
1 | +package org.thingsboard.server.controller; | |
2 | + | |
3 | +import org.junit.After; | |
4 | +import org.junit.Assert; | |
5 | +import org.junit.Before; | |
6 | +import org.junit.Test; | |
7 | +import org.thingsboard.server.common.data.Device; | |
8 | +import org.thingsboard.server.common.data.EntityView; | |
9 | +import org.thingsboard.server.common.data.Tenant; | |
10 | +import org.thingsboard.server.common.data.User; | |
11 | +import org.thingsboard.server.common.data.security.Authority; | |
12 | + | |
13 | +import java.util.Arrays; | |
14 | + | |
15 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
16 | +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; | |
17 | + | |
18 | +public abstract class BaseEntityViewControllerTest extends AbstractControllerTest { | |
19 | + | |
20 | + private Tenant savedTenant; | |
21 | + private User tenantAdmin; | |
22 | + private Device testDevice; | |
23 | + | |
24 | + @Before | |
25 | + public void beforeTest() throws Exception { | |
26 | + loginSysAdmin(); | |
27 | + | |
28 | + Device device = new Device(); | |
29 | + device.setName("Test device"); | |
30 | + device.setType("default"); | |
31 | + testDevice = doPost("/api/device", device, Device.class); | |
32 | + | |
33 | + Tenant tenant = new Tenant(); | |
34 | + tenant.setTitle("My tenant"); | |
35 | + savedTenant = doPost("/api/tenant", tenant, Tenant.class); | |
36 | + | |
37 | + Assert.assertNotNull(savedTenant); | |
38 | + | |
39 | + tenantAdmin = new User(); | |
40 | + tenantAdmin.setAuthority(Authority.TENANT_ADMIN); | |
41 | + tenantAdmin.setTenantId(savedTenant.getId()); | |
42 | + tenantAdmin.setEmail("tenant2@thingsboard.org"); | |
43 | + tenantAdmin.setFirstName("Joe"); | |
44 | + tenantAdmin.setLastName("Downs"); | |
45 | + | |
46 | + tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1"); | |
47 | + } | |
48 | + | |
49 | + @After | |
50 | + public void afterTest() throws Exception { | |
51 | + loginSysAdmin(); | |
52 | + | |
53 | + doDelete("/api/tenant/" + savedTenant.getId().getId().toString()) | |
54 | + .andExpect(status().isOk()); | |
55 | + } | |
56 | + | |
57 | + @Test | |
58 | + public void testSaveEntityViewWithIdOfDevice() throws Exception { | |
59 | + EntityView view = new EntityView(); | |
60 | + view.setEntityId(testDevice.getId()); | |
61 | + view.setName("Test entity view"); | |
62 | + view.setKeys(Arrays.asList("key1", "key2", "key3")); | |
63 | + EntityView savedView = doPost("/api/entity-view", view, EntityView.class); | |
64 | + | |
65 | + Assert.assertNotNull(savedView); | |
66 | + Assert.assertNotNull(savedView.getId()); | |
67 | + Assert.assertTrue(savedView.getCreatedTime() > 0); | |
68 | + Assert.assertEquals(savedTenant.getId(), savedView.getTenantId()); | |
69 | + Assert.assertNotNull(savedView.getCustomerId()); | |
70 | + Assert.assertEquals(NULL_UUID, savedView.getCustomerId().getId()); | |
71 | + Assert.assertEquals(savedView.getName(), savedView.getName()); | |
72 | + | |
73 | + savedView.setName("New test entity view"); | |
74 | + doPost("/api/entity-view", savedView, EntityView.class); | |
75 | + | |
76 | + EntityView foundEntityView = doGet("/api/device/" | |
77 | + + savedView.getId().getId().toString(), EntityView.class); | |
78 | + | |
79 | + Assert.assertEquals(foundEntityView.getName(), savedView.getName()); | |
80 | + } | |
81 | +} | ... | ... |
application/src/test/java/org/thingsboard/server/controller/nosql/EntityViewControllerNoSqlTest.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2018 The Thingsboard Authors | |
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 org.thingsboard.server.controller.nosql; | |
17 | + | |
18 | +import org.thingsboard.server.controller.BaseEntityViewControllerTest; | |
19 | +/** | |
20 | + * Created by Victor Basanets on 8/27/2017. | |
21 | + */ | |
22 | +public class EntityViewControllerNoSqlTest | |
23 | + extends BaseEntityViewControllerTest { | |
24 | +} | ... | ... |
application/src/test/java/org/thingsboard/server/controller/sql/EntityViewControllerSqlTest.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2018 The Thingsboard Authors | |
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 org.thingsboard.server.controller.sql; | |
17 | + | |
18 | +import org.thingsboard.server.controller.BaseEntityViewControllerTest; | |
19 | +import org.thingsboard.server.dao.service.DaoSqlTest; | |
20 | +/** | |
21 | + * Created by Victor Basanets on 8/27/2017. | |
22 | + */ | |
23 | +@DaoSqlTest | |
24 | +public class EntityViewControllerSqlTest | |
25 | + extends BaseEntityViewControllerTest { | |
26 | +} | ... | ... |