forked from googleworkspace/java-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnippetsTest.java
More file actions
160 lines (140 loc) · 6.59 KB
/
SnippetsTest.java
File metadata and controls
160 lines (140 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.google.api.services.slides.v1.model.*;
import java.io.IOException;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
public class SnippetsTest extends BaseTest {
private Snippets snippets;
private final String IMAGE_URL =
"https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
private final String TEMPLATE_PRESENTATION_ID = "1wJUN1B5CQ2wQOBzmz2apky48QNK1OsE2oNKHPMLpKDc";
private final String DATA_SPREADSHEET_ID = "14KaZMq2aCAGt5acV77zaA_Ps8aDt04G7T0ei4KiXLX8";
private final Integer CHART_ID = 1107320627;
private final String CUSTOMER_NAME = "Fake Customer";
@Before
public void createSnippets() {
this.snippets = new Snippets(this.service, this.driveService, this.sheetsService);
}
@Test
public void testCreatePresentation() throws IOException {
String presentationId = this.snippets.createPresentation("Title");
assertNotNull(presentationId);
this.deleteFileOnCleanup(presentationId);
}
@Test
public void testCopyPresentation() throws IOException {
String presentationId = this.createTestPresentation();
String copyId = this.snippets.copyPresentation(presentationId, "My Duplicate Presentation");
assertNotNull(copyId);
this.deleteFileOnCleanup(copyId);
}
@Test
public void testCreateSlide() throws IOException {
String presentationId = this.createTestPresentation();
BatchUpdatePresentationResponse response = this.snippets.createSlide(presentationId);
assertNotNull(response);
assertEquals(1, response.getReplies().size());
String pageId = response.getReplies().get(0).getCreateSlide().getObjectId();
assertNotNull(pageId);
}
@Test
public void testCreateTextBox() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
BatchUpdatePresentationResponse response =
this.snippets.createTextBoxWithText(presentationId, pageId);
assertEquals(2, response.getReplies().size());
String boxId = response.getReplies().get(0).getCreateShape().getObjectId();
assertNotNull(boxId);
}
@Test
public void testCreateImage() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
BatchUpdatePresentationResponse response = this.snippets.createImage(
presentationId, pageId, this.credential);
assertEquals(1, response.getReplies().size());
String imageId = response.getReplies().get(0).getCreateImage().getObjectId();
assertNotNull(imageId);
}
@Test
public void testTextMerge() throws IOException {
List<BatchUpdatePresentationResponse> responses =
this.snippets.textMerging(TEMPLATE_PRESENTATION_ID, DATA_SPREADSHEET_ID);
for (BatchUpdatePresentationResponse response: responses) {
String presentationId = response.getPresentationId();
assertNotNull(presentationId);
assertEquals(3, response.getReplies().size());
int numReplacements = 0;
for (Response resp : response.getReplies()) {
numReplacements += resp.getReplaceAllText().getOccurrencesChanged();
}
assertEquals(4, numReplacements);
this.deleteFileOnCleanup(presentationId);
}
}
@Test
public void testImageMerge() throws IOException {
BatchUpdatePresentationResponse response =
this.snippets.imageMerging(TEMPLATE_PRESENTATION_ID, IMAGE_URL, CUSTOMER_NAME);
String presentationId = response.getPresentationId();
assertNotNull(presentationId);
assertEquals(2, response.getReplies().size());
int numReplacements = 0;
for(Response resp: response.getReplies()) {
numReplacements += resp.getReplaceAllShapesWithImage().getOccurrencesChanged();
}
assertEquals(2, numReplacements);
this.deleteFileOnCleanup(presentationId);
}
@Test
public void testSimpleTextReplace() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
String boxId = this.createTestTextBox(presentationId, pageId);
BatchUpdatePresentationResponse response =
this.snippets.simpleTextReplace(presentationId, boxId, "MY NEW TEXT");
assertEquals(2, response.getReplies().size());
}
@Test
public void testTextStyleUpdate() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
String boxId = this.createTestTextBox(presentationId, pageId);
BatchUpdatePresentationResponse response =
this.snippets.textStyleUpdate(presentationId, boxId);
assertEquals(3, response.getReplies().size());
}
@Test
public void testCreateBulletText() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
String boxId = this.createTestTextBox(presentationId, pageId);
BatchUpdatePresentationResponse response =
this.snippets.createBulletedText(presentationId, boxId);
assertEquals(1, response.getReplies().size());
}
@Test
public void testCreateSheetsChart() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
BatchUpdatePresentationResponse response =
this.snippets.createSheetsChart(
presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID);
assertEquals(1, response.getReplies().size());
String chartId = response.getReplies().get(0).getCreateSheetsChart().getObjectId();
assertNotNull(chartId);
}
@Test
public void testRefreshSheetsChart() throws IOException {
String presentationId = this.createTestPresentation();
String pageId = this.createTestSlide(presentationId);
String chartId =
this.createTestSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID);
BatchUpdatePresentationResponse response =
this.snippets.refreshSheetsChart(presentationId, chartId);
assertEquals(1, response.getReplies().size());
}
}