2008-03-13 07:50:50 -04:00
|
|
|
/* ====================================================================
|
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
|
|
|
|
|
|
|
package org.apache.poi.xssf.usermodel;
|
|
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
2008-03-16 20:10:17 -04:00
|
|
|
import org.apache.poi.xssf.model.StylesTable;
|
|
|
|
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
|
2008-03-13 07:50:50 -04:00
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
|
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
|
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
|
|
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STBorderStyle;
|
|
|
|
|
|
|
|
|
|
|
|
public class TestXSSFCellStyle extends TestCase {
|
|
|
|
|
2008-03-16 20:10:17 -04:00
|
|
|
private StylesTable stylesTable;
|
|
|
|
private CTBorder ctBorderA;
|
|
|
|
private CTBorder ctBorderB;
|
2008-03-13 07:50:50 -04:00
|
|
|
private CTXf cellStyleXf;
|
|
|
|
private CTXf cellXf;
|
|
|
|
private XSSFCellStyle cellStyle;
|
|
|
|
|
|
|
|
public void setUp() {
|
2008-03-16 20:10:17 -04:00
|
|
|
stylesTable = new StylesTable();
|
|
|
|
|
|
|
|
CTStylesheet ctStylesheet = stylesTable._getRawStylesheet();
|
|
|
|
|
|
|
|
// Until we do XSSFBorder properly, cheat
|
|
|
|
ctBorderA = CTBorder.Factory.newInstance();
|
|
|
|
long borderId = stylesTable.putBorder(ctBorderA);
|
|
|
|
assertEquals(0, borderId);
|
|
|
|
|
|
|
|
XSSFCellBorder borderB = new XSSFCellBorder();
|
|
|
|
ctBorderB = borderB.getCTBorder();
|
|
|
|
assertEquals(1, stylesTable.putBorder(borderB));
|
|
|
|
|
2008-03-13 07:50:50 -04:00
|
|
|
cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
|
|
|
|
cellStyleXf.setBorderId(0);
|
|
|
|
cellXf = ctStylesheet.addNewCellXfs().addNewXf();
|
|
|
|
cellXf.setXfId(0);
|
2008-03-16 20:10:17 -04:00
|
|
|
cellStyle = new XSSFCellStyle(cellXf, cellStyleXf, stylesTable);
|
2008-03-13 07:50:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderBottom() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals((short)1, cellStyle.getBorderBottom());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderBottomAsString() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewBottom().setStyle(STBorderStyle.THIN);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals("thin", cellStyle.getBorderBottomAsString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderRight() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals((short)2, cellStyle.getBorderRight());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderRightAsString() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewRight().setStyle(STBorderStyle.MEDIUM);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals("medium", cellStyle.getBorderRightAsString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderLeft() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals((short)3, cellStyle.getBorderLeft());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderLeftAsString() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewLeft().setStyle(STBorderStyle.DASHED);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals("dashed", cellStyle.getBorderLeftAsString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetBorderTop() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals((short)7, cellStyle.getBorderTop());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testGetTopBottomAsString() {
|
2008-03-16 20:10:17 -04:00
|
|
|
ctBorderA.addNewTop().setStyle(STBorderStyle.HAIR);
|
2008-03-13 07:50:50 -04:00
|
|
|
assertEquals("hair", cellStyle.getBorderTopAsString());
|
|
|
|
}
|
|
|
|
}
|