Skip to content

Commit 7f1661e

Browse files
zaqifathishlg
authored andcommitted
remove try/catch block in lowlevel package
1 parent a6a189b commit 7f1661e

23 files changed

+1076
-1165
lines changed
Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,55 @@
1-
package org.bimserver.tests.lowlevel;
2-
3-
import static org.junit.Assert.assertEquals;
4-
5-
/******************************************************************************
6-
* Copyright (C) 2009-2019 BIMserver.org
7-
*
8-
* This program is free software: you can redistribute it and/or modify
9-
* it under the terms of the GNU Affero General Public License as
10-
* published by the Free Software Foundation, either version 3 of the
11-
* License, or (at your option) any later version.
12-
*
13-
* This program is distributed in the hope that it will be useful,
14-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16-
* GNU Affero General Public License for more details.
17-
*
18-
* You should have received a copy of the GNU Affero General Public License
19-
* along with this program. If not, see {@literal<http://www.gnu.org/licenses/>}.
20-
*****************************************************************************/
21-
22-
import static org.junit.Assert.fail;
1+
package org.bimserver.tests.lowlevel;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
/******************************************************************************
6+
* Copyright (C) 2009-2019 BIMserver.org
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see {@literal<http://www.gnu.org/licenses/>}.
20+
*****************************************************************************/
2321

2422
import org.bimserver.interfaces.objects.SProject;
2523
import org.bimserver.plugins.services.BimServerClientInterface;
24+
import org.bimserver.shared.ChannelConnectionException;
2625
import org.bimserver.shared.UsernamePasswordAuthenticationInfo;
26+
import org.bimserver.shared.exceptions.ServiceException;
2727
import org.bimserver.shared.interfaces.LowLevelInterface;
2828
import org.bimserver.test.TestWithEmbeddedServer;
2929
import org.junit.Test;
3030

3131
public class TestAddReferenceWithOpposite extends TestWithEmbeddedServer {
3232

3333
@Test
34-
public void test() {
35-
try {
36-
// Create a new BimServerClient with authentication
37-
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
38-
39-
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
40-
41-
// Create a new project
42-
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
43-
44-
// Start a transaction
45-
Long tid = lowLevelInterface.startTransaction(newProject.getOid());
46-
47-
Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
48-
Long ifcBuildingOid = lowLevelInterface.createObject(tid, "IfcBuilding", true);
49-
lowLevelInterface.addReference(tid, ifcBuildingOid, "ContainsElements", ifcRelContainedInSpatialStructureOid);
50-
51-
lowLevelInterface.commitTransaction(tid, "Initial", false);
52-
53-
tid = lowLevelInterface.startTransaction(newProject.getOid());
54-
assertEquals(ifcBuildingOid, lowLevelInterface.getReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure"));
55-
} catch (Exception e) {
56-
e.printStackTrace();
57-
fail(e.getMessage());
58-
}
34+
public void test() throws ServiceException, ChannelConnectionException {
35+
// Create a new BimServerClient with authentication
36+
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
37+
38+
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
39+
40+
// Create a new project
41+
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
42+
43+
// Start a transaction
44+
Long tid = lowLevelInterface.startTransaction(newProject.getOid());
45+
46+
Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
47+
Long ifcBuildingOid = lowLevelInterface.createObject(tid, "IfcBuilding", true);
48+
lowLevelInterface.addReference(tid, ifcBuildingOid, "ContainsElements", ifcRelContainedInSpatialStructureOid);
49+
50+
lowLevelInterface.commitTransaction(tid, "Initial", false);
51+
52+
tid = lowLevelInterface.startTransaction(newProject.getOid());
53+
assertEquals(ifcBuildingOid, lowLevelInterface.getReference(tid, ifcRelContainedInSpatialStructureOid, "RelatingStructure"));
5954
}
6055
}
Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
package org.bimserver.tests.lowlevel;
2-
3-
/******************************************************************************
4-
* Copyright (C) 2009-2019 BIMserver.org
5-
*
6-
* This program is free software: you can redistribute it and/or modify
7-
* it under the terms of the GNU Affero General Public License as
8-
* published by the Free Software Foundation, either version 3 of the
9-
* License, or (at your option) any later version.
10-
*
11-
* This program is distributed in the hope that it will be useful,
12-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-
* GNU Affero General Public License for more details.
15-
*
16-
* You should have received a copy of the GNU Affero General Public License
17-
* along with this program. If not, see {@literal<http://www.gnu.org/licenses/>}.
18-
*****************************************************************************/
19-
1+
package org.bimserver.tests.lowlevel;
2+
3+
/******************************************************************************
4+
* Copyright (C) 2009-2019 BIMserver.org
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see {@literal<http://www.gnu.org/licenses/>}.
18+
*****************************************************************************/
19+
2020
import static org.junit.Assert.fail;
2121

2222
import org.bimserver.interfaces.objects.SProject;
2323
import org.bimserver.plugins.services.BimServerClientInterface;
24+
import org.bimserver.shared.ChannelConnectionException;
2425
import org.bimserver.shared.UsernamePasswordAuthenticationInfo;
25-
import org.bimserver.shared.exceptions.ErrorCode;
26+
import org.bimserver.shared.exceptions.ServiceException;
2627
import org.bimserver.shared.exceptions.UserException;
2728
import org.bimserver.shared.interfaces.LowLevelInterface;
2829
import org.bimserver.test.TestWithEmbeddedServer;
@@ -31,40 +32,35 @@
3132
public class TestAddReferenceWithOppositeExisting extends TestWithEmbeddedServer {
3233

3334
@Test
34-
public void test() {
35+
public void test() throws ServiceException, ChannelConnectionException {
36+
// Create a new BimServerClient with authentication
37+
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
38+
39+
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
40+
41+
// Create a new project
42+
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
43+
44+
// Start a transaction
45+
Long tid = lowLevelInterface.startTransaction(newProject.getOid());
46+
47+
Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
48+
Long ifcBuildingOid1 = lowLevelInterface.createObject(tid, "IfcBuilding", true);
49+
Long ifcBuildingOid2 = lowLevelInterface.createObject(tid, "IfcBuilding", true);
50+
lowLevelInterface.addReference(tid, ifcBuildingOid1, "ContainsElements", ifcRelContainedInSpatialStructureOid);
51+
52+
lowLevelInterface.commitTransaction(tid, "Initial", false);
53+
54+
tid = lowLevelInterface.startTransaction(newProject.getOid());
55+
lowLevelInterface.addReference(tid, ifcBuildingOid2, "ContainsElements", ifcRelContainedInSpatialStructureOid);
3556
try {
36-
// Create a new BimServerClient with authentication
37-
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
38-
39-
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
40-
41-
// Create a new project
42-
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
43-
44-
// Start a transaction
45-
Long tid = lowLevelInterface.startTransaction(newProject.getOid());
46-
47-
Long ifcRelContainedInSpatialStructureOid = lowLevelInterface.createObject(tid, "IfcRelContainedInSpatialStructure", true);
48-
Long ifcBuildingOid1 = lowLevelInterface.createObject(tid, "IfcBuilding", true);
49-
Long ifcBuildingOid2 = lowLevelInterface.createObject(tid, "IfcBuilding", true);
50-
lowLevelInterface.addReference(tid, ifcBuildingOid1, "ContainsElements", ifcRelContainedInSpatialStructureOid);
51-
52-
lowLevelInterface.commitTransaction(tid, "Initial", false);
53-
54-
tid = lowLevelInterface.startTransaction(newProject.getOid());
55-
lowLevelInterface.addReference(tid, ifcBuildingOid2, "ContainsElements", ifcRelContainedInSpatialStructureOid);
56-
try {
57-
lowLevelInterface.commitTransaction(tid, "2", false);
58-
} catch (UserException e) {
57+
lowLevelInterface.commitTransaction(tid, "2", false);
58+
} catch (UserException e) {
5959
// if (e.getErrorCode() != ErrorCode.SET_REFERENCE_FAILED_OPPOSITE_ALREADY_SET) {
60-
fail("Didn't get the right errormessage");
60+
fail("Didn't get the right errormessage");
6161
// }
62-
} finally {
63-
fail("Expected error code");
64-
}
65-
} catch (Exception e) {
66-
e.printStackTrace();
67-
fail(e.getMessage());
62+
} finally {
63+
fail("Expected error code");
6864
}
6965
}
7066
}

Tests/test/org/bimserver/tests/lowlevel/TestChangeRoomNumbers.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,52 @@
1717
* along with this program. If not, see {@literal<http://www.gnu.org/licenses/>}.
1818
*****************************************************************************/
1919

20-
import static org.junit.Assert.fail;
21-
20+
import java.io.IOException;
2221
import java.net.URL;
2322
import java.nio.file.Paths;
2423

2524
import org.bimserver.emf.IfcModelInterface;
2625
import org.bimserver.interfaces.objects.SDeserializerPluginConfiguration;
2726
import org.bimserver.interfaces.objects.SProject;
2827
import org.bimserver.interfaces.objects.SSerializerPluginConfiguration;
29-
import org.bimserver.models.ifc2x3tc1.IfcRoot;
3028
import org.bimserver.models.ifc2x3tc1.IfcSpace;
3129
import org.bimserver.plugins.services.BimServerClientInterface;
30+
import org.bimserver.shared.ChannelConnectionException;
3231
import org.bimserver.shared.UsernamePasswordAuthenticationInfo;
32+
import org.bimserver.shared.exceptions.BimServerClientException;
33+
import org.bimserver.shared.exceptions.ServiceException;
3334
import org.bimserver.shared.interfaces.LowLevelInterface;
3435
import org.bimserver.test.TestWithEmbeddedServer;
35-
import org.junit.Test;
36-
37-
public class TestChangeRoomNumbers extends TestWithEmbeddedServer {
38-
39-
@Test
40-
public void test() {
41-
try {
42-
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
43-
bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
44-
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
45-
46-
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
47-
48-
SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
49-
bimServerClient.checkinSync(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
50-
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
51-
52-
SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
53-
54-
bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
55-
56-
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
57-
long tid = lowLevelInterface.startTransaction(newProject.getOid());
36+
import org.junit.Test;
37+
38+
public class TestChangeRoomNumbers extends TestWithEmbeddedServer {
39+
40+
@Test
41+
public void test() throws ServiceException, ChannelConnectionException, IOException, BimServerClientException {
42+
BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
43+
bimServerClient.getSettingsInterface().setCacheOutputFiles(false);
44+
LowLevelInterface lowLevelInterface = bimServerClient.getLowLevelInterface();
45+
46+
SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
47+
48+
SDeserializerPluginConfiguration suggestedDeserializerForExtension = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
49+
bimServerClient.checkinSync(newProject.getOid(), "initial", suggestedDeserializerForExtension.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
50+
newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
51+
52+
SSerializerPluginConfiguration serializer = bimServerClient.getServiceInterface().getSerializerByName("Ifc2x3tc1 (Streaming)");
53+
54+
bimServerClient.download(newProject.getLastRevisionId(), serializer.getOid(), Paths.get("test1.ifc"));
55+
56+
IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
57+
long tid = lowLevelInterface.startTransaction(newProject.getOid());
58+
59+
int id = 1;
60+
for (IfcSpace ifcSpace : model.getAll(IfcSpace.class)) {
61+
bimServerClient.getLowLevelInterface().setStringAttribute(tid, ifcSpace.getOid(), "Name", "New room number " + (id++));
62+
}
63+
64+
long roid = lowLevelInterface.commitTransaction(tid, "v2", false);
5865

59-
int id = 1;
60-
for (IfcSpace ifcSpace : model.getAll(IfcSpace.class)) {
61-
bimServerClient.getLowLevelInterface().setStringAttribute(tid, ifcSpace.getOid(), "Name", "New room number " + (id++));
62-
}
63-
64-
long roid = lowLevelInterface.commitTransaction(tid, "v2", false);
65-
66-
bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
67-
} catch (Exception e) {
68-
e.printStackTrace();
69-
fail(e.getMessage());
70-
}
71-
}
66+
bimServerClient.download(roid, serializer.getOid(), Paths.get("test3.ifc"));
67+
}
7268
}

0 commit comments

Comments
 (0)