Skip to content

Commit 5e919f2

Browse files
committed
update test code.
1 parent 13dfdf9 commit 5e919f2

14 files changed

+612
-59
lines changed

src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
import java.io.ByteArrayInputStream;
1717
import java.io.IOException;
18-
import java.util.ArrayList;
19-
import java.util.List;
18+
import java.util.*;
2019

2120
import static com.aliyun.oss.common.parser.RequestMarshallers.*;
2221

@@ -1035,4 +1034,57 @@ public void testDeleteVpcipRequestMarshaller() {
10351034
Assert.assertEquals("test-vip", vip);
10361035
}
10371036

1037+
@Test
1038+
public void testSetBucketInventoryRequestMarshaller() {
1039+
1040+
InventoryConfiguration config = new InventoryConfiguration();
1041+
1042+
byte[] data = setBucketInventoryRequestMarshaller.marshall(config);
1043+
ByteArrayInputStream is = new ByteArrayInputStream(data);
1044+
1045+
SAXBuilder builder = new SAXBuilder();
1046+
Document doc = null;
1047+
try {
1048+
doc = builder.build(is);
1049+
} catch (JDOMException e) {
1050+
e.printStackTrace();
1051+
} catch (IOException e) {
1052+
e.printStackTrace();
1053+
}
1054+
1055+
Element root = doc.getRootElement();
1056+
Assert.assertEquals(root.getChild("Id"), null);
1057+
Assert.assertEquals(root.getChild("IsEnabled"), null);
1058+
Assert.assertEquals(root.getChild("IncludedObjectVersions"), null);
1059+
Assert.assertEquals(root.getChild("Filter"), null);
1060+
Assert.assertEquals(root.getChild("Schedule"), null);
1061+
Assert.assertEquals(root.getChild("OptionalFields"), null);
1062+
Assert.assertEquals(root.getChild("Destination"), null);
1063+
1064+
config = new InventoryConfiguration();
1065+
config.setOptionalFields(new ArrayList<String>());
1066+
config.setDestination(new InventoryDestination().withOSSBucketDestination(new InventoryOSSBucketDestination()));
1067+
1068+
data = setBucketInventoryRequestMarshaller.marshall(config);
1069+
is = new ByteArrayInputStream(data);
1070+
1071+
try {
1072+
doc = builder.build(is);
1073+
} catch (JDOMException e) {
1074+
e.printStackTrace();
1075+
} catch (IOException e) {
1076+
e.printStackTrace();
1077+
}
1078+
1079+
root = doc.getRootElement();
1080+
Assert.assertEquals(root.getChild("Id"), null);
1081+
Assert.assertEquals(root.getChild("IsEnabled"), null);
1082+
Assert.assertEquals(root.getChild("IncludedObjectVersions"), null);
1083+
Assert.assertEquals(root.getChild("Filter"), null);
1084+
Assert.assertEquals(root.getChild("Schedule"), null);
1085+
Assert.assertEquals(root.getChild("OptionalFields"), null);
1086+
Assert.assertNotNull(root.getChild("Destination"));
1087+
1088+
}
1089+
10381090
}

src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3669,4 +3669,187 @@ public void testListVpcPolicyResultResponseParser() {
36693669
Assert.assertTrue(false);
36703670
}
36713671
}
3672+
3673+
@Test
3674+
public void testparseGetBucketInventoryConfig() {
3675+
InputStream instream = null;
3676+
String respBody;
3677+
3678+
respBody = "" +
3679+
"<InventoryConfiguration>\n" +
3680+
"</InventoryConfiguration>";
3681+
3682+
try {
3683+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3684+
} catch (UnsupportedEncodingException e) {
3685+
Assert.fail("UnsupportedEncodingException");
3686+
}
3687+
3688+
try {
3689+
ResponseParsers.parseGetBucketInventoryConfig(instream);
3690+
Assert.assertTrue(true);
3691+
} catch (ResponseParseException e) {
3692+
Assert.assertTrue(false);
3693+
} catch (Exception e) {
3694+
Assert.assertTrue(false);
3695+
}
3696+
3697+
respBody = "" +
3698+
"<InventoryConfiguration>\n" +
3699+
" <Filter>\n" +
3700+
" </Filter>\n" +
3701+
" <Schedule>\n" +
3702+
" </Schedule>\n" +
3703+
" <Destination>\n" +
3704+
" </Destination>\n" +
3705+
"</InventoryConfiguration>";
3706+
3707+
try {
3708+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3709+
} catch (UnsupportedEncodingException e) {
3710+
Assert.fail("UnsupportedEncodingException");
3711+
}
3712+
3713+
try {
3714+
ResponseParsers.parseGetBucketInventoryConfig(instream);
3715+
Assert.assertTrue(true);
3716+
} catch (ResponseParseException e) {
3717+
Assert.assertTrue(false);
3718+
} catch (Exception e) {
3719+
Assert.assertTrue(false);
3720+
}
3721+
3722+
respBody = "" +
3723+
"<InventoryConfiguration>\n" +
3724+
" <Filter>\n" +
3725+
" </Filter>\n" +
3726+
" <Schedule>\n" +
3727+
" </Schedule>\n" +
3728+
" <Destination>\n" +
3729+
" <OSSBucketDestination>\n" +
3730+
" </OSSBucketDestination>\n" +
3731+
" </Destination>\n" +
3732+
"</InventoryConfiguration>";
3733+
3734+
try {
3735+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3736+
} catch (UnsupportedEncodingException e) {
3737+
Assert.fail("UnsupportedEncodingException");
3738+
}
3739+
3740+
try {
3741+
ResponseParsers.parseGetBucketInventoryConfig(instream);
3742+
Assert.assertTrue(true);
3743+
} catch (ResponseParseException e) {
3744+
Assert.assertTrue(false);
3745+
} catch (Exception e) {
3746+
Assert.assertTrue(false);
3747+
}
3748+
3749+
respBody = "" +
3750+
"<InventoryConfiguration>\n" +
3751+
" <Filter>\n" +
3752+
" </Filter>\n" +
3753+
" <Schedule>\n" +
3754+
" </Schedule>\n" +
3755+
" <Destination>\n" +
3756+
" <OSSBucketDestination>\n" +
3757+
" <Encryption>\n" +
3758+
" </Encryption>\n" +
3759+
" </OSSBucketDestination>\n" +
3760+
" </Destination>\n" +
3761+
"</InventoryConfiguration>";
3762+
3763+
try {
3764+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3765+
} catch (UnsupportedEncodingException e) {
3766+
Assert.fail("UnsupportedEncodingException");
3767+
}
3768+
3769+
try {
3770+
ResponseParsers.parseGetBucketInventoryConfig(instream);
3771+
Assert.assertTrue(true);
3772+
} catch (ResponseParseException e) {
3773+
Assert.assertTrue(false);
3774+
} catch (Exception e) {
3775+
Assert.assertTrue(false);
3776+
}
3777+
3778+
respBody = "invalid";
3779+
3780+
try {
3781+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3782+
} catch (UnsupportedEncodingException e) {
3783+
Assert.fail("UnsupportedEncodingException");
3784+
}
3785+
3786+
try {
3787+
ResponseParsers.parseGetBucketInventoryConfig(instream);
3788+
Assert.assertTrue(false);
3789+
} catch (ResponseParseException e) {
3790+
Assert.assertTrue(true);
3791+
} catch (Exception e) {
3792+
Assert.assertTrue(false);
3793+
}
3794+
3795+
try {
3796+
ResponseParsers.parseGetBucketInventoryConfig(null);
3797+
Assert.assertTrue(false);
3798+
} catch (ResponseParseException e) {
3799+
Assert.assertTrue(true);
3800+
} catch (Exception e) {
3801+
Assert.assertTrue(false);
3802+
}
3803+
}
3804+
3805+
@Test
3806+
public void testparseListBucketInventoryConfigurations() {
3807+
InputStream instream = null;
3808+
String respBody;
3809+
3810+
respBody = "" +
3811+
"<ListInventoryConfiguration>\n" +
3812+
"</ListInventoryConfiguration>";
3813+
3814+
try {
3815+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3816+
} catch (UnsupportedEncodingException e) {
3817+
Assert.fail("UnsupportedEncodingException");
3818+
}
3819+
3820+
try {
3821+
ResponseParsers.parseListBucketInventoryConfigurations(instream);
3822+
Assert.assertTrue(true);
3823+
} catch (ResponseParseException e) {
3824+
Assert.assertTrue(false);
3825+
} catch (Exception e) {
3826+
Assert.assertTrue(false);
3827+
}
3828+
3829+
respBody = "invalid";
3830+
3831+
try {
3832+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
3833+
} catch (UnsupportedEncodingException e) {
3834+
Assert.fail("UnsupportedEncodingException");
3835+
}
3836+
3837+
try {
3838+
ResponseParsers.parseListBucketInventoryConfigurations(instream);
3839+
Assert.assertTrue(false);
3840+
} catch (ResponseParseException e) {
3841+
Assert.assertTrue(true);
3842+
} catch (Exception e) {
3843+
Assert.assertTrue(false);
3844+
}
3845+
3846+
try {
3847+
ResponseParsers.parseListBucketInventoryConfigurations(null);
3848+
Assert.assertTrue(false);
3849+
} catch (ResponseParseException e) {
3850+
Assert.assertTrue(true);
3851+
} catch (Exception e) {
3852+
Assert.assertTrue(false);
3853+
}
3854+
}
36723855
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.aliyun.oss.crypto;
21+
22+
import junit.framework.Assert;
23+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
24+
import org.junit.Test;
25+
26+
import java.security.SecureRandom;
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
30+
public class ContentCryptoMaterialTest {
31+
32+
@Test
33+
public void testConstruction() {
34+
byte[] iv = new byte[2];
35+
byte[] encryptedCEK = new byte[2];
36+
byte[] encryptedIV = new byte[2];
37+
Map<String, String> matDesc = new HashMap<String, String>();
38+
ContentCryptoMaterial material = new ContentCryptoMaterial(null, iv,null, encryptedCEK,encryptedIV,null, matDesc);
39+
Assert.assertEquals(material.hashCode(), -196513505);
40+
41+
material = new ContentCryptoMaterial(null, iv,"", encryptedCEK,encryptedIV,"", matDesc);
42+
Assert.assertEquals(material.hashCode(), -196513505);
43+
}
44+
}

0 commit comments

Comments
 (0)