blob: 87153715eb3a7125958c5723e2842311b0506a14 [file] [log] [blame]
Zhomart Mukhamejanovf4d280c2018-04-17 13:20:22 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
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
17package com.example.android.systemupdatersample;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertSame;
21
22import android.support.test.filters.SmallTest;
23import android.support.test.runner.AndroidJUnit4;
24
25import org.junit.Rule;
26import org.junit.Test;
27import org.junit.rules.ExpectedException;
28import org.junit.runner.RunWith;
29
30/**
31 * Tests for {@link UpdateConfig}
32 */
33@RunWith(AndroidJUnit4.class)
34@SmallTest
35public class UpdateConfigTest {
36
37 private static final String JSON_NON_STREAMING =
38 "{\"name\": \"vip update\", \"url\": \"file:///builds/a.zip\", "
39 + " \"type\": \"NON_STREAMING\"}";
40
41 private static final String JSON_STREAMING =
42 "{\"name\": \"vip update 2\", \"url\": \"http://foo.bar/a.zip\", "
43 + "\"type\": \"STREAMING\"}";
44
45 @Rule
46 public final ExpectedException thrown = ExpectedException.none();
47
48 @Test
49 public void fromJson_parsesJsonConfigWithoutMetadata() throws Exception {
50 UpdateConfig config = UpdateConfig.fromJson(JSON_NON_STREAMING);
51 assertEquals("name is parsed", "vip update", config.getName());
52 assertEquals("stores raw json", JSON_NON_STREAMING, config.getRawJson());
53 assertSame("type is parsed", UpdateConfig.TYPE_NON_STREAMING, config.getInstallType());
54 assertEquals("url is parsed", "file:///builds/a.zip", config.getUrl());
55 }
56
57 @Test
58 public void getUpdatePackageFile_throwsErrorIfStreaming() throws Exception {
59 UpdateConfig config = UpdateConfig.fromJson(JSON_STREAMING);
60 thrown.expect(RuntimeException.class);
61 config.getUpdatePackageFile();
62 }
63
64 @Test
65 public void getUpdatePackageFile_throwsErrorIfNotAFile() throws Exception {
66 String json = "{\"name\": \"upd\", \"url\": \"http://foo.bar\","
67 + " \"type\": \"NON_STREAMING\"}";
68 UpdateConfig config = UpdateConfig.fromJson(json);
69 thrown.expect(RuntimeException.class);
70 config.getUpdatePackageFile();
71 }
72
73 @Test
74 public void getUpdatePackageFile_works() throws Exception {
75 UpdateConfig c = UpdateConfig.fromJson(JSON_NON_STREAMING);
76 assertEquals("correct path", "/builds/a.zip", c.getUpdatePackageFile().getAbsolutePath());
77 }
78
79}