Skip to content

Commit bc7821c

Browse files
EXM-43284: Fixed a bug about the options from the plugin preferences page; Added TCs;
1 parent 3a0f888 commit bc7821c

File tree

3 files changed

+100
-8
lines changed

3 files changed

+100
-8
lines changed

src/main/java/com/oxygenxml/prolog/updater/prolog/content/PrologContentCreator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,22 @@ private void loadOptions() {
330330
updateMapProlog = Boolean.parseBoolean(value);
331331

332332
value = optionsStorage.getOption(OptionKeys.TOPIC_SET_CREATOR, String.valueOf(true));
333-
setTopicCreator = Boolean.parseBoolean(value);
333+
setTopicCreator = Boolean.parseBoolean(value) && updateTopicProlog;
334334
value = optionsStorage.getOption(OptionKeys.MAP_SET_CREATOR, String.valueOf(true));
335-
setMapCreator = Boolean.parseBoolean(value);
335+
setMapCreator = Boolean.parseBoolean(value) && updateMapProlog;
336336
value = optionsStorage.getOption(OptionKeys.TOPIC_UPDATE_CONTRIBUTOR, String.valueOf(true));
337-
updateTopicContributor = Boolean.parseBoolean(value);
337+
updateTopicContributor = Boolean.parseBoolean(value) && updateTopicProlog;
338338
value = optionsStorage.getOption(OptionKeys.MAP_UPDATE_CONTRIBUTOR, String.valueOf(true));
339-
updateMapContributor = Boolean.parseBoolean(value);
339+
updateMapContributor = Boolean.parseBoolean(value) && updateMapProlog;
340340

341341
value = optionsStorage.getOption(OptionKeys.TOPIC_SET_CREATED_DATE, String.valueOf(true));
342-
setTopicCreatedDate = Boolean.parseBoolean(value);
342+
setTopicCreatedDate = Boolean.parseBoolean(value) && updateTopicProlog;
343343
value = optionsStorage.getOption(OptionKeys.MAP_SET_CREATED_DATE, String.valueOf(true));
344-
setMapCreatedDate = Boolean.parseBoolean(value);
344+
setMapCreatedDate = Boolean.parseBoolean(value) && updateMapProlog;
345345
value = optionsStorage.getOption(OptionKeys.TOPIC_UPDATE_REVISED_DATES, String.valueOf(true));
346-
updateTopicRevisedDate = Boolean.parseBoolean(value);
346+
updateTopicRevisedDate = Boolean.parseBoolean(value) && updateTopicProlog;
347347
value = optionsStorage.getOption(OptionKeys.MAP_UPDATE_REVISED_DATES, String.valueOf(true));
348-
updateMapRevisedDate = Boolean.parseBoolean(value);
348+
updateMapRevisedDate = Boolean.parseBoolean(value) && updateMapProlog;
349349
}
350350
}
351351
}

src/test/java/com/oxygenxml/prolog/updater/prolog/content/PrologContentCreatorMapTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,50 @@ protected String createLocalDate(String dateFormat) {
266266
"<topicmeta><critdates><!--name--><revised modified=\"2017-12-04\"/></critdates></topicmeta>", prologFragment);
267267

268268
}
269+
270+
/**
271+
* <p>
272+
* <b>Description:</b> Test the functionality when MAP_ENABLE_UPDATE_ON_SAVE
273+
* option is false and other options are set to true.
274+
* </p>
275+
*
276+
*/
277+
@PrepareForTest({ PluginWorkspaceProvider.class })
278+
@Test
279+
public void testUpdateDisable_EXM_43284() {
280+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.MAP_ENABLE_UPDATE_ON_SAVE, Boolean.TRUE.toString()))
281+
.thenReturn(Boolean.FALSE.toString());
282+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.MAP_SET_CREATOR, Boolean.TRUE.toString()))
283+
.thenReturn(Boolean.TRUE.toString());
284+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.MAP_SET_CREATED_DATE, Boolean.TRUE.toString()))
285+
.thenReturn(Boolean.TRUE.toString());
286+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.MAP_UPDATE_CONTRIBUTOR, Boolean.TRUE.toString()))
287+
.thenReturn(Boolean.TRUE.toString());
288+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.MAP_UPDATE_REVISED_DATES, Boolean.TRUE.toString()))
289+
.thenReturn(Boolean.TRUE.toString());
290+
291+
PrologContentCreator prologContentCreator = new PrologContentCreator(AUTHOR_NAME, "name");
292+
293+
// Get the prolog according to settings when document is new.
294+
String prologFragment = prologContentCreator.getPrologFragment(true, DocumentType.MAP);
295+
// The prolog fragment is not generated.
296+
assertNull("The fragment shouldn't be generated.", prologFragment);
297+
298+
// Get the prolog according to settings when document isn't new.
299+
prologFragment = prologContentCreator.getPrologFragment(false, DocumentType.MAP);
300+
// The prolog fragment is not generated.
301+
assertNull("The fragment shouldn't be generated.", prologFragment);
302+
303+
// Check the author element from the prolog
304+
String prologAuthorElement = prologContentCreator.getPrologAuthorElement(true, DocumentType.MAP);
305+
assertNull("The fragment shouldn't be generated.", prologAuthorElement);
306+
prologAuthorElement = prologContentCreator.getPrologAuthorElement(false, DocumentType.MAP);
307+
assertNull("The fragment shouldn't be generated.", prologAuthorElement);
308+
309+
// Check the date element from the prolog
310+
String dateFragment = prologContentCreator.getDateFragment(true, DocumentType.MAP);
311+
assertNull("The fragment shouldn't be generated.", dateFragment);
312+
dateFragment = prologContentCreator.getDateFragment(false, DocumentType.TOPIC);
313+
assertNull("The fragment shouldn't be generated.", dateFragment);
314+
}
269315
}

src/test/java/com/oxygenxml/prolog/updater/prolog/content/PrologContentCreatorTopicTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,50 @@ protected String createLocalDate(String dateFormat) {
265265
// Check the generated prolog fragment.
266266

267267
}
268+
269+
/**
270+
* <p>
271+
* <b>Description:</b> Test the functionality when TOPIC_ENABLE_UPDATE_ON_SAVE
272+
* option is false and other options are set to true.
273+
* </p>
274+
*
275+
*/
276+
@PrepareForTest({ PluginWorkspaceProvider.class })
277+
@Test
278+
public void testUpdateDisable_EXM_43284() {
279+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.TOPIC_ENABLE_UPDATE_ON_SAVE, Boolean.TRUE.toString()))
280+
.thenReturn(Boolean.FALSE.toString());
281+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.TOPIC_SET_CREATOR, Boolean.TRUE.toString()))
282+
.thenReturn(Boolean.TRUE.toString());
283+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.TOPIC_SET_CREATED_DATE, Boolean.TRUE.toString()))
284+
.thenReturn(Boolean.TRUE.toString());
285+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.TOPIC_UPDATE_CONTRIBUTOR, Boolean.TRUE.toString()))
286+
.thenReturn(Boolean.TRUE.toString());
287+
Mockito.when(wsOptionsStorage.getOption(OptionKeys.TOPIC_UPDATE_REVISED_DATES, Boolean.TRUE.toString()))
288+
.thenReturn(Boolean.TRUE.toString());
289+
290+
PrologContentCreator prologContentCreator = new PrologContentCreator(AUTHOR_NAME, "name");
291+
292+
// Get the prolog according to settings when document is new.
293+
String prologFragment = prologContentCreator.getPrologFragment(true, DocumentType.TOPIC);
294+
// The prolog fragment is not generated.
295+
assertNull("The fragment shouldn't be generated.", prologFragment);
296+
297+
// Get the prolog according to settings when document isn't new.
298+
prologFragment = prologContentCreator.getPrologFragment(false, DocumentType.TOPIC);
299+
// The prolog fragment is not generated.
300+
assertNull("The fragment shouldn't be generated.", prologFragment);
301+
302+
// Check the author element from the prolog
303+
String prologAuthorElement = prologContentCreator.getPrologAuthorElement(true, DocumentType.TOPIC);
304+
assertNull("The fragment shouldn't be generated.", prologAuthorElement);
305+
prologAuthorElement = prologContentCreator.getPrologAuthorElement(false, DocumentType.TOPIC);
306+
assertNull("The fragment shouldn't be generated.", prologAuthorElement);
307+
308+
// Check the date element from the prolog
309+
String dateFragment = prologContentCreator.getDateFragment(true, DocumentType.TOPIC);
310+
assertNull("The fragment shouldn't be generated.", dateFragment);
311+
dateFragment = prologContentCreator.getDateFragment(false, DocumentType.TOPIC);
312+
assertNull("The fragment shouldn't be generated.", dateFragment);
313+
}
268314
}

0 commit comments

Comments
 (0)