|
| 1 | +package org.geoserver.geofence.services.rest.impl; |
| 2 | + |
| 3 | +import org.geoserver.geofence.core.model.enums.AdminGrantType; |
| 4 | +import org.geoserver.geofence.core.model.enums.GrantType; |
| 5 | +import org.geoserver.geofence.services.rest.exception.BadRequestRestEx; |
| 6 | +import org.geoserver.geofence.services.rest.model.RESTBatch; |
| 7 | +import org.geoserver.geofence.services.rest.model.RESTBatchOperation; |
| 8 | +import org.geoserver.geofence.services.rest.model.RESTInputAdminRule; |
| 9 | +import org.geoserver.geofence.services.rest.model.RESTInputGroup; |
| 10 | +import org.geoserver.geofence.services.rest.model.RESTInputRule; |
| 11 | +import org.geoserver.geofence.services.rest.model.RESTInputUser; |
| 12 | +import org.geoserver.geofence.services.rest.model.RESTOutputRule; |
| 13 | +import org.geoserver.geofence.services.rest.model.RESTRulePosition; |
| 14 | +import org.geoserver.geofence.services.rest.model.util.IdName; |
| 15 | +import org.geoserver.geofence.services.rest.model.util.RESTBatchOperationFactory; |
| 16 | +import org.junit.Test; |
| 17 | + |
| 18 | +import javax.ws.rs.core.Response; |
| 19 | +import java.util.ArrayList; |
| 20 | + |
| 21 | +import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertNotNull; |
| 23 | +import static org.junit.Assert.assertNull; |
| 24 | +import static org.junit.Assert.fail; |
| 25 | + |
| 26 | +public class RESTBatchServiceImplTest extends RESTBaseTest { |
| 27 | + |
| 28 | + |
| 29 | + @Test |
| 30 | + public void testBatchInsertAdminRule() { |
| 31 | + RESTInputAdminRule adminRule=new RESTInputAdminRule(); |
| 32 | + adminRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); |
| 33 | + adminRule.setWorkspace("ws99"); |
| 34 | + adminRule.setRolename("roleName00"); |
| 35 | + adminRule.setGrant(AdminGrantType.ADMIN); |
| 36 | + RESTBatchOperation restBatchOperation=new RESTBatchOperation(); |
| 37 | + restBatchOperation.setService(RESTBatchOperation.ServiceName.adminrules); |
| 38 | + restBatchOperation.setType(RESTBatchOperation.TypeName.insert); |
| 39 | + restBatchOperation.setPayload(adminRule); |
| 40 | + RESTInputAdminRule adminRule2=new RESTInputAdminRule(); |
| 41 | + adminRule2.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); |
| 42 | + adminRule2.setWorkspace("ws999"); |
| 43 | + adminRule2.setRolename("roleName00"); |
| 44 | + adminRule2.setGrant(AdminGrantType.USER); |
| 45 | + RESTBatchOperation restBatchOperation2=new RESTBatchOperation(); |
| 46 | + restBatchOperation2.setService(RESTBatchOperation.ServiceName.adminrules); |
| 47 | + restBatchOperation2.setType(RESTBatchOperation.TypeName.insert); |
| 48 | + restBatchOperation2.setPayload(adminRule2); |
| 49 | + RESTBatch restBatch=new RESTBatch(); |
| 50 | + restBatch.add(restBatchOperation); |
| 51 | + restBatch.add(restBatchOperation2); |
| 52 | + assertEquals(200,restBatchService.exec(restBatch).getStatus()); |
| 53 | + |
| 54 | + long result=restAdminRuleService.count(null,true,"roleName00",false,null,null,false,null,false); |
| 55 | + assertEquals(2,result); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testBatchUpdateAdminRule() { |
| 60 | + RESTInputAdminRule adminRule=new RESTInputAdminRule(); |
| 61 | + adminRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); |
| 62 | + adminRule.setWorkspace("ws99"); |
| 63 | + adminRule.setRolename("roleName11"); |
| 64 | + adminRule.setGrant(AdminGrantType.ADMIN); |
| 65 | + RESTInputAdminRule adminRule2=new RESTInputAdminRule(); |
| 66 | + adminRule2.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); |
| 67 | + adminRule2.setWorkspace("ws999"); |
| 68 | + adminRule2.setRolename("roleName11"); |
| 69 | + adminRule2.setGrant(AdminGrantType.USER); |
| 70 | + Long id=(Long)restAdminRuleService.insert(adminRule).getEntity(); |
| 71 | + Long id2=(Long)restAdminRuleService.insert(adminRule2).getEntity(); |
| 72 | + RESTBatchOperation restBatchOperation=new RESTBatchOperation(); |
| 73 | + restBatchOperation.setService(RESTBatchOperation.ServiceName.adminrules); |
| 74 | + restBatchOperation.setType(RESTBatchOperation.TypeName.update); |
| 75 | + restBatchOperation.setId(id); |
| 76 | + adminRule.setWorkspace("ws00"); |
| 77 | + adminRule.setPosition(null); |
| 78 | + restBatchOperation.setPayload(adminRule); |
| 79 | + |
| 80 | + RESTBatchOperation restBatchOperation2=new RESTBatchOperation(); |
| 81 | + restBatchOperation2.setService(RESTBatchOperation.ServiceName.adminrules); |
| 82 | + restBatchOperation2.setType(RESTBatchOperation.TypeName.update); |
| 83 | + restBatchOperation2.setId(id2); |
| 84 | + adminRule2.setWorkspace("ws000"); |
| 85 | + adminRule2.setPosition(null); |
| 86 | + restBatchOperation2.setPayload(adminRule2); |
| 87 | + |
| 88 | + RESTBatch batch=new RESTBatch(); |
| 89 | + batch.add(restBatchOperation); |
| 90 | + batch.add(restBatchOperation2); |
| 91 | + restBatchService.exec(batch); |
| 92 | + |
| 93 | + assertEquals("ws00",restAdminRuleService.get(id).getWorkspace()); |
| 94 | + assertEquals("ws000",restAdminRuleService.get(id2).getWorkspace()); |
| 95 | + |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + @Test |
| 100 | + public void testBatchDeleteAdminRule() { |
| 101 | + RESTInputAdminRule adminRule=new RESTInputAdminRule(); |
| 102 | + adminRule.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); |
| 103 | + adminRule.setWorkspace("ws99"); |
| 104 | + adminRule.setRolename("roleName22"); |
| 105 | + adminRule.setGrant(AdminGrantType.ADMIN); |
| 106 | + RESTInputAdminRule adminRule2=new RESTInputAdminRule(); |
| 107 | + adminRule2.setPosition(new RESTRulePosition(RESTRulePosition.RulePosition.offsetFromTop,0)); |
| 108 | + adminRule2.setWorkspace("ws999"); |
| 109 | + adminRule2.setRolename("roleName22"); |
| 110 | + adminRule2.setGrant(AdminGrantType.USER); |
| 111 | + Long id=(Long)restAdminRuleService.insert(adminRule).getEntity(); |
| 112 | + Long id2=(Long)restAdminRuleService.insert(adminRule2).getEntity(); |
| 113 | + RESTBatchOperation restBatchOperation=new RESTBatchOperation(); |
| 114 | + restBatchOperation.setService(RESTBatchOperation.ServiceName.adminrules); |
| 115 | + restBatchOperation.setType(RESTBatchOperation.TypeName.delete); |
| 116 | + restBatchOperation.setId(id); |
| 117 | + |
| 118 | + RESTBatchOperation restBatchOperation2=new RESTBatchOperation(); |
| 119 | + restBatchOperation2.setService(RESTBatchOperation.ServiceName.adminrules); |
| 120 | + restBatchOperation2.setType(RESTBatchOperation.TypeName.delete); |
| 121 | + restBatchOperation2.setId(id2); |
| 122 | + |
| 123 | + RESTBatch batch=new RESTBatch(); |
| 124 | + batch.add(restBatchOperation); |
| 125 | + batch.add(restBatchOperation2); |
| 126 | + restBatchService.exec(batch); |
| 127 | + long result=restAdminRuleService.count(null,true,"roleName22",false,null,null,false,null,false); |
| 128 | + assertEquals(0,result); |
| 129 | + |
| 130 | + } |
| 131 | +} |
0 commit comments